Created
November 10, 2011 16:12
-
-
Save fabriziomachado/1355246 to your computer and use it in GitHub Desktop.
codeigniter-acedemic/application/workers/resize_worker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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