verot / class.upload.php

This PHP class uploads files and manipulates images very easily. It is in fact as much as an image processing class than it is an upload class. Compatible with PHP 4, 5, 7 and 8. Supports processing of local files, uploaded files, files sent through XMLHttpRequest.
http://www.verot.net/php_class_upload.htm
GNU General Public License v2.0
847 stars 358 forks source link

fixed png to jpg conversion while resize #91

Closed akwatra closed 6 years ago

akwatra commented 6 years ago

when you used $handle->image_convert = 'jpg'; and $handle->image_resize = true; it was taking old file extension name as destination and image type data was resultant corrept image.

verot commented 6 years ago

I don't understand your pull request. Can you copy here the logs produced by the class, which show the problem? (so before your patch)

akwatra commented 6 years ago

To reproduce error at your end: upload png image $handle->image_convert = 'jpg';

and do resize: $handle->image_background_color = '#FFFFFF'; $handle->image_ratio_fill = true; $handle->image_resize = true; $handle->image_x = 300; $handle->image_y = 230; $handle->process($current_img_dir);

Image extension should be ".jpg" but it was creating png as this was taking $this->file_dst_pathname but this should take new file ext while creating jpg image in look into LINE 4795
switch($this->image_convert) { case 'jpeg': case 'jpg': if (!$return_mode) { $result = @imagejpeg($image_dst, $this->file_dst_path . '/' . $this->file_dst_name_body .'.jpg', $this->jpeg_quality);

in log also taking the wrong extension, in this patch log also has to correct yet.

######## LOG ######### system information

verot commented 6 years ago

I see. In fact, you are in an edge case, with _file_src_nameext which is empty. You are trying to convert a local file, which is an image, but there is no file extension. And in the code, there is:

if ($this->file_src_name_ext) $this->file_dst_name_ext  = $this->image_convert;
$this->log .= '- new file name ext : ' . $this->image_convert . '<br />';

It was by design, to not add an extension is there is no extension to start with, but it didn't deal with the case of converting an image with no extension.

I have applied the proper correction here d3e1301

Thank you for spotting the issue.

akwatra commented 6 years ago

Hi Verot, I have tested with browser proper via form upload and that file had extension png, so after image created, it keeps the png ext as a bug and did not rename to jpg.

issue came, when i was trying to open that image and that was not showing data in viewer, then I dig into and found the bug. You please double check once at your end with png an extention image.

verot commented 6 years ago

I did try with PNG, and it converted to JPEG, with a .jpg extension:

system information

verot commented 6 years ago

Try with the new master, it should work for you too.

akwatra commented 6 years ago

It's Working Now! Thx.