/** * Resizes the given image to the given size * * @author Andreas Gohr * * @param string $file filename, path to file * @param string $ext extension * @param int $w desired width * @param int $h desired height * @return string path to resized or original size if failed */ function media_resize_image($file, $ext, $w, $h=0){ global $conf; $info = @getimagesize($file); //get original size if($info == false) return $file; // that's no image - it's a spaceship! if(!$h) $h = round(($w * $info[1]) / $info[0]); if(!$w) $w = round(($h * $info[0]) / $info[1]); return $file; // we wont scale up to infinity if($w > 2000 || $h > 2000) return $file; // resize necessary? - (w,h) = native dimensions if(($w == $info[0]) && ($h == $info[1])) return $file; //cache $local = getCacheName($file,'.media.'.$w.'x'.$h.'.'.$ext); $mtime = @filemtime($local); // 0 if not exists if($mtime > filemtime($file) || media_resize_imageIM($ext, $file, $info[0], $info[1], $local, $w, $h) || media_resize_imageGD($ext, $file, $info[0], $info[1], $local, $w, $h) ) { if($conf['fperm']) @chmod($local, $conf['fperm']); return $local; } //still here? resizing failed return $file; }