diff options
author | Pavel Vitis <Pavel.Vitis@seznam.cz> | 2005-09-11 16:02:25 +0200 |
---|---|---|
committer | Pavel Vitis <Pavel.Vitis@seznam.cz> | 2005-09-11 16:02:25 +0200 |
commit | 683757541c99dba48c30662ba2b60db34352165f (patch) | |
tree | ca03eb0e0c7d1abf7aec40e1c099a84370f4cbb0 /lib/exe/fetch.php | |
parent | 42208b030af8151de0f39d22d4b04264db93e498 (diff) | |
download | rpg-683757541c99dba48c30662ba2b60db34352165f.tar.gz rpg-683757541c99dba48c30662ba2b60db34352165f.tar.bz2 |
support for ImageMagicks convert in fetch.php
This patch allows one to set $conf['im_convert'] to use ImageMagick
instead of PHPs libGD to resize images. convert is more powerful
than libGD - it can resize animated gifs for example.
darcs-hash:20050911140225-c484b-10fbb66d003c839debc98edf814e261bddea3aa6.gz
Diffstat (limited to 'lib/exe/fetch.php')
-rw-r--r-- | lib/exe/fetch.php | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index 8f5dd40bc..1f8b690fb 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -114,7 +114,9 @@ function get_resized($file, $ext, $w, $h=0){ $local = getCacheName($file,'.media.'.$w.'x'.$h.'.'.$ext); $mtime = @filemtime($local); // 0 if not exists - if( $mtime > filemtime($file) || resize_image($ext,$file,$info[0],$info[1],$local,$w,$h) ){ + if( $mtime > filemtime($file) || + resize_imageIM($ext,$file,$info[0],$info[1],$local,$w,$h) || + resize_imageGD($ext,$file,$info[0],$info[1],$local,$w,$h) ){ return $local; } //still here? resizing failed @@ -143,23 +145,25 @@ function calc_cache($cache){ * wanted * * @author Andreas Gohr <andi@splitbrain.org> + * @author Pavel Vitis <Pavel.Vitis@seznam.cz> */ function get_from_URL($url,$ext,$cache){ global $conf; - $url = strtolower($url); - $local = getCacheName($url,".media.$ext"); + $local = getCacheName(strtolower($url),".media.$ext"); $mtime = @filemtime($local); // 0 if not exists //decide if download needed: - - // never cache exists but no endless cache not exists or expired - if( $cache == 0 || ($mtime != 0 && $cache != -1) || $mtime < time()-$cache ){ - if(io_download($url,$local)){ - return $local; - }else{ - return false; - } + if( $cache == 0 || // never cache + ($mtime != 0 && $cache != -1) || // exists but no endless cache + ($mtime == 0) || // not exists + ($cache != -1 && $mtime < time()-$cache) // expired + ){ + if(io_download($url,$local)){ + return $local; + }else{ + return false; + } } //if cache exists use it else @@ -170,11 +174,34 @@ function get_from_URL($url,$ext,$cache){ } /** - * resize images + * resize images using external ImageMagick convert program + * + * @author Pavel Vitis <Pavel.Vitis@seznam.cz> + * @author Andreas Gohr <andi@splitbrain.org> + */ +function resize_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){ + global $conf; + + // check if convert is configured and available + if(!@is_executable($conf['im_convert'])) return false; + + // prepare command + $cmd = $conf['im_convert']; + $cmd .= ' -resize '.$to_w.'x'.$to_h.'!'; + $cmd .= " $from $to"; + + @exec($cmd,$out,$retval); + if ($retval == 0) return true; + + return false; +} + +/** + * resize images using PHP's libGD support * * @author Andreas Gohr <andi@splitbrain.org> */ -function resize_image($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){ +function resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){ global $conf; if($conf['gdlib'] < 1) return false; //no GDlib available or wanted |