baraja-core / shop-product

Advanced product manager with administration interface in PHP. Compatible with Baraja CMS.
https://baraja.cz/cms
MIT License
4 stars 0 forks source link

Image processing after upload #7

Open janbarasek opened 2 years ago

janbarasek commented 2 years ago
$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);
}

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

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

welcome[bot] commented 2 years ago

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