Skip to content

Instantly share code, notes, and snippets.

@hdragomir
Created September 2, 2010 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdragomir/562067 to your computer and use it in GitHub Desktop.
Save hdragomir/562067 to your computer and use it in GitHub Desktop.
on the fly image resizer
<?php
define('cache', realpath('./cacheddata/icons/'));
$h = 28;
$w = 28;
$iurl = &$_GET['i'];
$file = cache . DIRECTORY_SEPARATOR . sha1("$w/$h/$iurl").'.jpg';
header("Content-type: image/jpeg");
if(file_exists($file)){
$th = imagecreatefromjpeg($file);
imagejpeg($th);
} else {
$image = imagecreatefromjpeg(($iurl));
list($x, $y) = @getimagesize ($iurl);
$th = imagecreatetruecolor($w, $h);
imagecopyresampled($th, $image, 0,0, 0,0, $w,$h, $x,$y);
imagedestroy($image);
imagejpeg($th, $file, 80);
chmod($file, 0777);
imagejpeg($th);
imagedestroy($th);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment