@@ -18,6 +18,7 @@ class ImageResize
18
18
19
19
public $ quality_jpg = 75 ;
20
20
public $ quality_png = 0 ;
21
+ public $ quality_truecolor = TRUE ;
21
22
22
23
public $ interlace = 1 ;
23
24
@@ -143,29 +144,41 @@ public function save($filename, $image_type = null, $quality = null, $permission
143
144
{
144
145
$ image_type = $ image_type ?: $ this ->source_type ;
145
146
146
- $ dest_image = imagecreatetruecolor ($ this ->getDestWidth (), $ this ->getDestHeight ());
147
-
148
- imageinterlace ($ dest_image , $ this ->interlace );
149
-
150
147
switch ($ image_type ) {
151
148
case IMAGETYPE_GIF :
149
+ $ dest_image = imagecreatetruecolor ($ this ->getDestWidth (), $ this ->getDestHeight ());
150
+
152
151
$ background = imagecolorallocatealpha ($ dest_image , 255 , 255 , 255 , 1 );
153
152
imagecolortransparent ($ dest_image , $ background );
154
153
imagefill ($ dest_image , 0 , 0 , $ background );
155
154
imagesavealpha ($ dest_image , true );
156
155
break ;
157
156
158
157
case IMAGETYPE_JPEG :
158
+ $ dest_image = imagecreatetruecolor ($ this ->getDestWidth (), $ this ->getDestHeight ());
159
+
159
160
$ background = imagecolorallocate ($ dest_image , 255 , 255 , 255 );
160
161
imagefilledrectangle ($ dest_image , 0 , 0 , $ this ->getDestWidth (), $ this ->getDestHeight (), $ background );
161
162
break ;
162
163
163
164
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
+
164
175
imagealphablending ($ dest_image , false );
165
176
imagesavealpha ($ dest_image , true );
166
177
break ;
167
178
}
168
179
180
+ imageinterlace ($ dest_image , $ this ->interlace );
181
+
169
182
imagecopyresampled (
170
183
$ dest_image ,
171
184
$ this ->source_image ,
0 commit comments