Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
How can i create vector image with jpg image with php imagefilter

Please help me create vector image like this below, I tried to use image filter grayscale, however it is not creating the dark black I want, so if you can help me create dark black vector like this in PHP, that would be great.

This is the code below which I tried before, and it created a vector, but it was gray instead of black

from this image

this

to Image

this

My code is

if($effect){

            imagefilter($dst_img, IMG_FILTER_GRAYSCALE);
             
            
           //imagefilter($dst_img, IMG_FILTER_CONTRAST, -100);
        }

My Full code is

    function createThumbnail($imageName,$newWidth,$newHeight,$effect)
    {
        $uploadDir="assets/front/collage/images/9fd0c8fe";
        $path = $uploadDir . '/' . $imageName;

        $mime = getimagesize($path);

        if($mime['mime']=='image/png'){ $src_img = imagecreatefrompng($path); }
        if($mime['mime']=='image/jpg'){ $src_img = imagecreatefromjpeg($path); }
        if($mime['mime']=='image/jpeg'){ $src_img = imagecreatefromjpeg($path); }
        if($mime['mime']=='image/pjpeg'){ $src_img = imagecreatefromjpeg($path); }

        $old_x = imageSX($src_img);
        $old_y = imageSY($src_img);

        if($old_x > $old_y)
        {
            $thumb_w    =   $newWidth;
            $thumb_h    =   $old_y/$old_x*$newWidth;
        }

        if($old_x < $old_y)
        {
            $thumb_w    =   $old_x/$old_y*$newHeight;
            $thumb_h    =   $newHeight;
        }

        if($old_x == $old_y)
        {
            $thumb_w    =   $newWidth;
            $thumb_h    =   $newHeight;
        }

        
        $dst_img        =   ImageCreateTrueColor($thumb_w,$thumb_h);

        imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

        if($effect){

            imagefilter($dst_img, IMG_FILTER_GRAYSCALE);
             
            
           //imagefilter($dst_img, IMG_FILTER_CONTRAST, -100);
        }
        // New save location
        //$new_thumb_loc = $moveToDir . $imageName;

        if($mime['mime']=='image/png'){ $result = imagepng($dst_img); }
        if($mime['mime']=='image/jpg'){ $result = imagejpeg($dst_img); }
        if($mime['mime']=='image/jpeg'){ $result = imagejpeg($dst_img); }
        if($mime['mime']=='image/pjpeg'){ $result = imagejpeg($dst_img); }
        
        

        imagedestroy($dst_img);
        imagedestroy($src_img);
        return $result;
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This worked for me:

<?php

createThumbnail('test.png',50,50,true);
function createThumbnail($imageName,$newWidth,$newHeight,$effect)
    {
        $uploadDir="assets/front/collage/images/9fd0c8fe";
        $path = $uploadDir . '/' . $imageName;

        $mime = getimagesize($path);

        if($mime['mime']=='image/png'){ $src_img = imagecreatefrompng($path); }
        if($mime['mime']=='image/jpg'){ $src_img = imagecreatefromjpeg($path); }
        if($mime['mime']=='image/jpeg'){ $src_img = imagecreatefromjpeg($path); }
        if($mime['mime']=='image/pjpeg'){ $src_img = imagecreatefromjpeg($path); }

        $old_x = imagesx($src_img);
        $old_y = imagesy($src_img);

        if($old_x > $old_y)
        {
            $thumb_w    =   $newWidth;
            $thumb_h    =   $old_y/$old_x*$newWidth;
        }

        if($old_x < $old_y)
        {
            $thumb_w    =   $old_x/$old_y*$newHeight;
            $thumb_h    =   $newHeight;
        }

        if($old_x == $old_y)
        {
            $thumb_w    =   $newWidth;
            $thumb_h    =   $newHeight;
        }
        
        $dst_img        =   imagecreatetruecolor($thumb_w,$thumb_h);
        
        imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);



        if($effect){

            imagefilter($dst_img, IMG_FILTER_GRAYSCALE);
            imagefilter($dst_img, IMG_FILTER_CONTRAST, -100);
             
        }
        // New save location
        //$new_thumb_loc = $moveToDir . $imageName;
        header('Content-Type: ' . $mime['mime']); //Changed for my test
        if($mime['mime']=='image/png'){ $result = imagepng($dst_img); }
        if($mime['mime']=='image/jpg'){ $result = imagejpeg($dst_img); }
        if($mime['mime']=='image/jpeg'){ $result = imagejpeg($dst_img); }
        if($mime['mime']=='image/pjpeg'){ $result = imagejpeg($dst_img); }
            return $result;
    }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda