Mega Code Archive

 
Categories / Php / Graphics
 

Server side image process with imagemagick in PHP

<? //The code Below uses image magic without any filter in PHP code. //You can easily process an image at server side by changing the transform string. //it is a modified version of the code in the drupal //it works on both Unix and Windows. function image_convert($source, $dest, $filter) { $imagick_convert ="misc/image/convert.exe"; //your path here if (!$_imagick_convert) { print("you have to set correct image magic path!"); exit; } $source = _image_escape_shell($source); $dest = _image_escape_shell($dest); $err = exec("$imagick_convert $filter $source $dest"); return $err; } function _image_escape_shell($filename) { if (strstr($_SERVER["SERVER_SOFTWARE"], "Win32")) { return '"'.addslashes(_image_strip_name($filename)).'"'; } else { return escapeshellarg(_image_strip_name($filename)); } } function _image_strip_name($filename) { $filename = strtr(urldecode($filename), "ÁÉÍÓÚÑÀÈÌÒÙÄËÏÖÜÂÊÎÔÛáéíóúñàèìòùäëïöüâêîôûç ", "aeiounaeiouaeiouaeiouaeiounaeiouaeiouaeiouc_"); return strtolower(preg_replace("/[^A-Za-z0-9\.\-\+\/_]/","",$filename)); } function example_run() { $source = "/images/1.jpg"; $trasform_string .= " -draw 'image Over 40,40 400,400 temp/ball001.EPS' "; $r=_image_convert($source,$source,$trasform_string); } ?>