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 :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
                    $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);
Les images à partir desquelles 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