Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image processing after upload #7

Open
janbarasek opened this issue Jan 3, 2022 · 1 comment
Open

Image processing after upload #7

janbarasek opened this issue Jan 3, 2022 · 1 comment
Labels
enhancement New feature or request size/M

Comments

@janbarasek
Copy link
Member

  • If a PNG image was uploaded, automatically convert to JPG with 85% compression
$image = imagecreatefrompng($filePath);
$bg = imagecreatetruecolor(imagesx($image), imagesy($image));
imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
imagealphablending($bg, TRUE);
imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
imagedestroy($image);
$quality = 50; // 0 = worst / smaller file, 100 = better / bigger file 
imagejpeg($bg, $filePath . ".jpg", $quality);
imagedestroy($bg);

Or:

// Quality is a number between 0 (best compression) and 100 (best quality)
function png2jpg($originalFile, $outputFile, $quality) {
    $image = imagecreatefrompng($originalFile);
    imagejpeg($image, $outputFile, $quality);
    imagedestroy($image);
}
  • Remove EXIF data from JPG

https://stackoverflow.com/questions/3614925/remove-exif-data-from-jpg-using-php

https://www.php.net/manual/en/imagick.stripimage.php

@janbarasek janbarasek added enhancement New feature or request size/M labels Jan 3, 2022
@welcome
Copy link

welcome bot commented Jan 3, 2022

Thanks for opening your first issue here! Be sure to follow the issue template!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size/M
Projects
None yet
Development

No branches or pull requests

1 participant