Skip to content

Instantly share code, notes, and snippets.

@fabriziomachado
Created November 10, 2011 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabriziomachado/1355246 to your computer and use it in GitHub Desktop.
Save fabriziomachado/1355246 to your computer and use it in GitHub Desktop.
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