mreish Posted December 16, 2015 Share Posted December 16, 2015 I'm trying to write a script to demenostrate JPG lossy compression. The idea is to start with an image called copy-0000.jpg that is at 100% quality then save it 100 times at 50 quality renaming the copies as it goes. So each copy will be half the quality of the previous. $j = 0; for ($i = 0; $i < 100; $i ++) { $j ++; $fileToCompress = imagecreatefromjpeg('copy-' . sprintf('%04d',$i) . '.jpg'); imagejpeg($fileToCompress, 'copy-' . sprintf('%04d',$j) . '.jpg', 50); imagedestroy($fileToCompress); } But I wind up with 100 copies of the original, each at 50 quality. I am open for ideas. Link to comment https://forums.phpfreaks.com/topic/299786-need-help-with-script-that-copies-jpg-to-different-quality-settings/ Share on other sites More sharing options...
Barand Posted December 16, 2015 Share Posted December 16, 2015 But I wind up with 100 copies of the original, each at 50 quality. That is what you said you want to do. then save it 100 times at 50 quality renaming the copies as it goes If you want to reduce the quality each time then don't hard-code the "50", put it in a variable and reduce the value in each loop Link to comment https://forums.phpfreaks.com/topic/299786-need-help-with-script-that-copies-jpg-to-different-quality-settings/#findComment-1528060 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.