The resize png background becomes black, not transparent.

function resize($photo_src, $width, $name){ $parametr = getimagesize($photo_src); list($width_orig, $height_orig) = getimagesize($photo_src); $ratio_orig = $width_orig/$height_orig; $new_width = $width; $new_height = $width / $ratio_orig; $newpic = imagecreatetruecolor($new_width, $new_height); imagesavealpha( $newpic, true ); switch ( $parametr[2] ) { case 1: $image = imagecreatefromgif($photo_src); break; case 2: $image = imagecreatefromjpeg($photo_src); break; case 3: $image = imagecreatefrompng($photo_src); break; } imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); imagejpeg($newpic, $name, 100); return true; } 
  • JPEG has no alpha channel. Those. transparency cannot be made. I have not worked with images in PHP for a long time, try to save imagepng instead of imagejpeg - A1essandro

1 answer 1

if you are working with the GD library, then everything is very bad with the processing of the alpha channel, try using imageK - everything is much simpler and processing images when resizing is much easier ... the whole problem is transparency ...