Skip to content

Instantly share code, notes, and snippets.

@theonelucas
Created October 23, 2020 11:00
Show Gist options
  • Save theonelucas/fb4401cdd00cce9045e876aada263caa to your computer and use it in GitHub Desktop.
Save theonelucas/fb4401cdd00cce9045e876aada263caa to your computer and use it in GitHub Desktop.
<?php
ini_set('display_errors', 'On');
set_time_limit(-1);
$imgs = [
'/srv/http/jessica.jpg',
];
define('BR', '<br>');
foreach ($imgs as $img) {
$original = basename($img);
$path = dirname($img).'/';
$copy = '__temp__'.$original;
copy($path.$original, $path.$copy);
$i = 0;
$quality = 100;
while (filesize($path.$copy) > 100000) {
$i++;
$quality--;
unlink($path.$copy);
imagejpeg(imagecreatefromjpeg($path.$original), $path.$copy, $quality);
}
unlink($path.$original);
rename($path.$copy, $path.$original);
chmod($path.$original, 0777);
echo "$i iterations for file $original".BR;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment