0) mkdir($dir, $rights); } } list($width_orig, $height_orig) = getimagesize($_GET['file']); if(isset($_GET['imgWidth'])) $req_width = $width = $_GET['imgWidth']; else $req_width = $width = $width_orig; if(isset($_GET['imgHeight'])) $req_height = $height = $_GET['imgHeight']; else $req_height = $height = $height_orig; if(isset($_GET['crops'])) { $cache = 'crops'; } else { $cache = 'thumbs'; } if ($width_orig > $width or $height_orig > $height) { if(is_file("$cache/$width/$height/{$_GET['file']}")) { $imageDest = imagecreatefromjpeg("$cache/$width/$height/{$_GET['file']}"); } else { if(isset($_GET['crops'])) { $rapp_larg = $width_orig / $width; $rapp_alt = $height_orig / $height; if($rapp_larg > $rapp_alt) { $src_x = ($width_orig - ($width * $rapp_alt)) / 2; $width_orig -= $src_x * 2; } else if ($rapp_larg < $rapp_alt) { $src_y = ($height_orig - ($height * $rapp_larg)) / 2; $height_orig -= $src_y * 2; } } else { if ($width && ($width_orig < $height_orig)) { $width = round(($height / $height_orig) * $width_orig); } else { $height = round(($width / $width_orig) * $height_orig); } } $imageSrc = imagecreatefromjpeg($_GET['file']); // The recommended approach is the usage of the GD2.x functions. // Create an empty thumbnail image. $imageDest = imagecreatetruecolor($width, $height); // Try to create the thumbnail from the source image. imagecopyresampled($imageDest, $imageSrc, 0, 0, $src_x, $src_y, $width, $height, $width_orig, $height_orig); // save the thumbnail image into a file. $partial_path = explode("/", $_GET['file']); array_pop($partial_path); $partial_path = implode("/", $partial_path); mkdir_r("$cache/$req_width/$req_height/$partial_path"); chmod("$cache/$req_width/$req_height/$partial_path", 0777); imagejpeg($imageDest, "$cache/$req_width/$req_height/{$_GET['file']}", 90); } } else { $imageDest = imagecreatefromjpeg($_GET['file']); } imagejpeg($imageDest, NULL, 90); imagedestroy($imageSrc); imagedestroy($imageDest); ?>