@@ -18,6 +18,7 @@ class ImageResize
1818
1919 public $ quality_jpg = 75 ;
2020 public $ quality_png = 0 ;
21+ public $ quality_truecolor = TRUE ;
2122
2223 public $ interlace = 1 ;
2324
@@ -143,29 +144,41 @@ public function save($filename, $image_type = null, $quality = null, $permission
143144 {
144145 $ image_type = $ image_type ?: $ this ->source_type ;
145146
146- $ dest_image = imagecreatetruecolor ($ this ->getDestWidth (), $ this ->getDestHeight ());
147-
148- imageinterlace ($ dest_image , $ this ->interlace );
149-
150147 switch ($ image_type ) {
151148 case IMAGETYPE_GIF :
149+ $ dest_image = imagecreatetruecolor ($ this ->getDestWidth (), $ this ->getDestHeight ());
150+
152151 $ background = imagecolorallocatealpha ($ dest_image , 255 , 255 , 255 , 1 );
153152 imagecolortransparent ($ dest_image , $ background );
154153 imagefill ($ dest_image , 0 , 0 , $ background );
155154 imagesavealpha ($ dest_image , true );
156155 break ;
157156
158157 case IMAGETYPE_JPEG :
158+ $ dest_image = imagecreatetruecolor ($ this ->getDestWidth (), $ this ->getDestHeight ());
159+
159160 $ background = imagecolorallocate ($ dest_image , 255 , 255 , 255 );
160161 imagefilledrectangle ($ dest_image , 0 , 0 , $ this ->getDestWidth (), $ this ->getDestHeight (), $ background );
161162 break ;
162163
163164 case IMAGETYPE_PNG :
165+ if (!$ this ->quality_truecolor && !imageistruecolor ($ this ->source_image )) {
166+ $ dest_image = imagecreate ($ this ->getDestWidth (), $ this ->getDestHeight ());
167+
168+ $ background = imagecolorallocatealpha ($ dest_image , 255 , 255 , 255 , 1 );
169+ imagecolortransparent ($ dest_image , $ background );
170+ imagefill ($ dest_image , 0 , 0 , $ background );
171+ } else {
172+ $ dest_image = imagecreatetruecolor ($ this ->getDestWidth (), $ this ->getDestHeight ());
173+ }
174+
164175 imagealphablending ($ dest_image , false );
165176 imagesavealpha ($ dest_image , true );
166177 break ;
167178 }
168179
180+ imageinterlace ($ dest_image , $ this ->interlace );
181+
169182 imagecopyresampled (
170183 $ dest_image ,
171184 $ this ->source_image ,
0 commit comments