Créer une image avec un fond transparent ...
Posté : 15 mars 2020, 13:51
Bonjour à tous,
en fait, j'essaie de redimensionner une image avec un fond transparent mais malheureusement, j'obtiens toujours un fond noir.
Pourtant, j'ai essayé pas mal de choses mais je n'arrive pas à obtenir le résultat escompté.
Voici mon code :
Les images que j'ai voulu créer un thumbnail sont des images au format "jpg".
Avez-vous une idée du problème que je rencontre et qui ne me permet pas d'avoir un fond transparent ? Comme je le disais, j'ai toujours un fond noir.
Merci d'avance
Bon dimanche à tous.
Thierry
en fait, j'essaie de redimensionner une image avec un fond transparent mais malheureusement, j'obtiens toujours un fond noir.
Pourtant, j'ai essayé pas mal de choses mais je n'arrive pas à obtenir le résultat escompté.
Voici mon code :
Code : Tout sélectionner
$im_temp = imagecreatetruecolor($th_width, $th_height);
// preserve transparency
if ($file_mime_type == "image/gif" || $file_mime_type == "image/png")
{
imagecolortransparent($im_temp, imagecolorallocatealpha($im_temp, 255, 255, 255, 127));
imagealphablending($im_temp, false);
imagesavealpha($im_temp, true);
}
imageCopyResampled($im_temp, $im_old, 0, 0, 0, 0, $th_width, $th_height, $picture_width, $picture_height);
$x0 = ( $th_width - $th_max_width ) / 2;
$y0 = ( $th_height - $th_max_height ) / 2;
$im_new = imagecreatetruecolor($th_max_width, $th_max_height);
// preserve transparency
if ($file_mime_type == "image/gif" || $file_mime_type == "image/png")
{
imagecolortransparent($im_new, imagecolorallocatealpha($im_new, 255, 255, 255, 127));
imagealphablending($im_new, false);
imagesavealpha($im_new, true);
}
imagecopy($im_new, $im_temp, 0, 0, $x0, $y0, $th_max_width, $th_max_height);
Avez-vous une idée du problème que je rencontre et qui ne me permet pas d'avoir un fond transparent ? Comme je le disais, j'ai toujours un fond noir.
Merci d'avance
Bon dimanche à tous.
Thierry