[ create a new paste ] login | about

Link: http://codepad.org/w6iyLLdv    [ raw code | fork ]

PHP, pasted on Mar 10:
<?php
require_once 'functions.php';
if(!isset($_SERVER['DOCUMENT_ROOT'])){
  $_SERVER['DOCUMENT_ROOT'] = /* ... */;
}

if(isset($_GET['img'])){
  $id = urldecode($_GET['img']);
}else{
  die('unspecified');
}

$w = 150;
$h = 114;

$row = get_fields($id, array('name', 'ext'));
$image = $_SERVER['DOCUMENT_ROOT'] . '/images/' . $row['name'];

if (!file_exists($image)){
  die('invalid');
}
$cache = $_SERVER['DOCUMENT_ROOT'] . '/thumbs/' . $row['name'];
$cli = isset($_GET['context']) && $_GET['context'] == 'cli';

if(!file_exists($cache)){
  $thumb = cacheThumb($image);
}elseif(!$cli){
  $thumb = new Imagick($cache);
}

if(!$cli){
  header ('Content-Type: image/' . strtolower($thumb->getImageFormat()));
  echo $thumb->getImageBlob();
}else{
  exit(0);
}

function cacheThumb($image){
  global $cache, $w, $h, $firephp;
  $thumb = new Imagick($image);
  $thumb->flattenImages();
  $quotient = min($thumb->getImageWidth() / $w,
                  $thumb->getImageHeight() / $h);
  $thumb->cropImage($w * $quotient, $h * $quotient, 0, 0);
  $thumb->scaleImage($w, $h);
  $thumb->writeImage($cache);
  return $thumb;
}

?>


Create a new paste based on this one


Comments: