friend of israel   dAyVNeT   
- about you -
Unknown Browser on Unknown OS
CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
38.107.191.84
- blog -
<< September, 2010 >>sunmontuewedthufrisat   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30   
- quotation of the moment -
Kids, you tried your best and you failed miserably. The lesson is, never try.
Homer Simpson
This is a copy of the php image script I use for all of the pictures on this site, eventually I will add comments. It dynamically resizes pictures, and caches them so they can be accessed faster later.
<?
header("Content-type: image/jpeg");
header("Content-Disposition: inline;
filename=" . $_GET['image'] . '.jpg');
$cacheDir='put/image/cache/here';
$image = 'put/image/dir/here' . $_GET['image'] . '.jpg';
$newwidth = $_GET['width'];
$newheight = $_GET['height'];
if (!$_GET['image']) {
   $im=imageCreate(200,20);
   $bg=imageColorAllocate($im, 0, 0, 0);
   imageFilledRectangle($im, 0, 0, 200, 20, $bg);
   $fg=imageColorAllocate($im, 255, 255, 255);
   imagestring($im, 1, 5, 5,"No image file was specified", $fg);
   imagejpeg($im);
   imagedestroy($im);
   exit;
} if (!file_exists($image)) {
   $im=imageCreate(200,20);
   $bg=imageColorAllocate($im, 0, 0, 0);
   imageFilledRectangle($im, 0, 0, 200, 20, $bg);
   $fg=imageColorAllocate($im, 255, 255, 255);
   imageString($im, 1, 5, 5, $_GET['image'] . " does not exist", $fg);
   imagejpeg($im);
   imagedestroy($im);
   exit;
} list($width, $height)=getimagesize($image);
if ($newheight=='' || $newwidth=='') {
   $newheight=$height;
   $newwidth=$width;
}/* else if ($newheight=='' && $newwidth!='') {
   $newheight=($height)*($newwidth/$width);
   $newwidth=$width;
} else if ($newheight!='' && $newwidth='') {
   $newheight=$height;
   $newwidth=($width)*($newheight/$height);
}*/ $rotate=$_GET['rotate'];
$cacheName=$cacheDir . md5($image . '-r:' . ($rotate%4) . '-d:' . $newheight . 'x' . $newwidth) . '.jpg';
if (file_exists($cacheName)) {
   readfile($cacheName);
} else {
   $src=imageCreateFromJPEG($image);
   $im=imageCreateTrueColor($newwidth,$newheight);
   imagecopyresampled($im,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
   if ($rotate!='') {
      $im=imageRotate($im, ($rotate%4)*360/4, 0);
   }    if ($newwidth>100) {
      $brand=imageCreateFromPNG('images/brand.png');
      imageColorTransparent($brand, imagecolorallocate($brand, 255, 255, 255));
      imageCopyMerge($im, $brand, imagesx($im)/2-imagesx($brand)/2, imagesy($im)-imagesy($brand), 0, 0, imagesx($brand), imagesy($brand), 100);
   }    imagejpeg($im, $cacheName);
   imagejpeg($im);
   imagedestroy($src);
   imagedestroy($im);
} ?>


Creative Commons License
© 2006 dayv. some rights reserved.
eXTReMe Tracker