Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
304 views
in Q2A Core by
closed by

Question closed! → Just 15 min later I realized that the JPG format is only used when resizing!

This way I have implemented it in my old plugin as well :) good work gidgreen!

I disagree with the solution of always throwing back a JPEG.

With PNG you can save a lot of data and compress much better if it is an appropriate image. E.g. make a screenshot, you will notice PNG is much better in compressing it. Jpeg is better for real life photos.

I suggest changing the: function qa_image_constrain_data($imagedata, &$width, &$height, $maxwidth, $maxheight=null)

so that it returns a PNG image if the image uploaded was PNG. Code example:

$src = imagecreatefrompng($file['tmp_name']);

    // create new image
    $newImage = imagecreatetruecolor($newwidth,$newheight);

    // do the image resizing by copying from the original into $newImage image
    imagecopyresampled($newImage,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

    // write image to buffer and save in variable
    ob_start(); // stdout --> buffer
    imagejpeg($newImage,NULL,90); // do JPG instead of PNG
    $newImageToSave = ob_get_contents(); // store stdout in $newImageToSave
    ob_end_clean(); // clear buffer

    // remove images from php buffer
    imagedestroy($src);
    imagedestroy($newImage);
 

$blobid=qa_db_blob_create($newImageToSave, $extension, @$file['name'], $userid, $cookieid, qa_remote_ip_address()); // v1.5.4

Q2A version: 1.6.2
closed with the note: clarified
...