All pastes #777288 Raw Edit

Mine

public php v1 · immutable
·published 2007-11-16 18:03 UTC
rendered paste body
<?  $p_id  = floor($_GET['p_id']);  $file  = "photos/$p_id.jpg";  $thumb = "cache/thumbs/$p_id.jpg";  if(!file_exists($thumb)) {    if(file_exists($file)) {      $im    = imagecreatetruecolor(150,120);      $white = imagecolorallocate($im, 255, 255, 255);      imagefill($im, 0, 0, $white);      $info = getimagesize($file);      switch($info[2]) {        case 1:  $src = imagecreatefromgif($file);  break;        case 2:  $src = imagecreatefromjpeg($file); break;        case 3:  $src = imagecreatefrompng($file);  break;      }      if($src) {        $width  = $info[0];        $height = $info[1];        while($width > 150 || $height > 120) {          $scale = ($width > 150 ? 150 / $width : 120 / $height);          $width  *= $scale;          $height *= $scale;        }        imagecopyresampled($im, $src, (150-$width)/2, (120-$height)/2, 0, 0, $width, $height, $info[0], $info[1]);      }      header('Content-type: image/jpeg');      imagejpeg($im, $thumb, 85);    }  }  $last_modified     = gmdate('D, d M Y H:i:s', filemtime($thumb)) . ' GMT';  $etag              = sprintf('"thumb-%08X-%08X"', $p_id, filemtime($thumb));  if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {    $if_none_match = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);    if($if_none_match == $etag) {      header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');      exit;    }  }  if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {    $if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);    if($if_modified_since == $gmdate_mod) {      header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');      exit;    }  }  header("Last-Modified: $last_modified");  header("ETag: $etag");  header('Content-Length: ' . filesize($thumb));  header('Content-type: image/jpeg');  readfile($thumb);  exit;?>