Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
¿Cómo puedo crear una imagen vectorial con una imagen jpg con php imagefilter?

Ayúdenme a crear una imagen vectorial como esta a continuación, traté de usar el filtro de imagen en escala de grises, sin embargo, no está creando el negro oscuro que quiero, así que si pueden ayudarme a crear un vector negro oscuro como este en PHP, sería genial.

Este es el código a continuación que probé antes, y creó un vector, pero era gris en lugar de negro

de esta imagen

este

a la imagen

este

mi codigo es

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

Mi código completo es

 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 Respuestas
Responde la pregunta

0

Esto funcionó para mí:

 <?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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda