Frank
Frank

Reputation: 624

upload converted imagejpeg to server

This is a function that creates a .jpg file from an uploaded .png file.

$input_file = 'img/uploaded/'.$_SESSION['userid'].'-'.$_SESSION['username'].'.png';
$output_file = 'img/uploaded/'.$_SESSION['userid'].'-'.$_SESSION['username'].'.jpg';

$input = imagecreatefrompng($input_file);
list($width, $height) = getimagesize($input_file);
$output = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($output,  255, 255, 255);
imagefilledrectangle($output, 0, 0, $width, $height, $white);
imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
imagejpeg($output, $output_file);

What I would like to know is how to define a custom "quality" or compression-rate for the new JPEG image. In some other conversion-functions there is a possibility to choose between 0(max compression) and 100(max quality). Does anybody know how to do this in my case?

Upvotes: 0

Views: 480

Answers (1)

Samuil Banti
Samuil Banti

Reputation: 1795

The last parameter of imagejpeg() is "quality": This should set it to max quality:

imagejpeg($output, $output_file, 100);

For more info. check this out:

http://php.net/manual/en/function.imagejpeg.php

Upvotes: 2

Related Questions