3 # This plugin rescales uploaded images using ImageMagick(1), if an uploaded
4 # image file is larger than allowed in EWIKI_IMAGE_MAXSIZE.
6 # NOTE: ImageMagick can usually be found on UNIX sytems only, but you could
7 # of course utilize another commandline instead if your system provides a
12 $ewiki_plugins["image_resize"][] = "ewiki_binary_resize_image_magick";
15 function ewiki_binary_resize_image_magick(&$filename, &$type, $return=0) {
17 if (!filesize($filename)) {
21 if(filesize($filename) < EWIKI_IMAGE_MAXSIZE){
25 #-- temporary image file
26 $tmp_rescale = tempnam(EWIKI_TMP, "ewiki.img_resize_magick.tmp.");
27 $tmp_size = filesize($filename);
29 #-- initial rescale factor
30 $scale = sqrt(EWIKI_IMAGE_MAXSIZE / ($tmp_size + 1));
32 #-- try to rescale image
34 while ($loop && ($tmp_size > EWIKI_IMAGE_MAXSIZE)) {
36 @unlink($tmp_rescale);
37 copy($filename, $tmp_rescale);
39 $n = round($scale * 100);
40 exec("mogrify -scale $n%x$n% $tmp_rescale");
43 $scale = $scale * 0.95;
44 $tmp_size = filesize($tmp_rescale);
49 if ((filesize($tmp_rescale)) &&
50 (filesize($tmp_rescale) < filesize($filename)) &&
51 (filesize($tmp_rescale) < EWIKI_IMAGE_MAXSIZE))
54 $filename = $tmp_rescale;
58 @unlink($tmp_rescale);