Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
codeigniter-acedemic/application/workers/resize_worker.php
<?php
$gmw = new GearmanWorker();
$gmw->addServer();
$gmw->addFunction("resize_image", "resize_image");
# waiting for job
while($gmw->work()){
if($gmw->returnCode() != GEARMAN_SUCCESS) break;
}
function resize_image($job, $data=NULL)
{
/* get the name of the file to process */
list($file, $path) = unserialize($job->workload());
$path = '/home/fabrizio/public_html/dev.localhost/codeigniter-academic/assets/images/photos/';
$src = $path.$file;
/* create our imagmagick object */
$imagem = new Imagick();
$imagem->readImage($src);
if(!$imagem) return false;
# resize image
for($percent=100; $percent >= 10; $percent-=20)
{
$new_file_resizable = $path."{$percent}_{$file}";
/* resize image */
$new_size = round($imagem->getImageWidth() * ($percent/100));
$imagem->thumbnailImage($new_size, 0);
$imagem->writeImage($new_file_resizable);
$msg_return = "$new_file_resizable - new-size: $new_size" . PHP_EOL;
echo $msg_return;
#exec("notify-send --hint=string:x-canonical-private-synchronous: -i 'dialog-ok' '". $dest ."'");
sleep(2);
}
$imagem->destroy();
return true;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment