Subversion Repositories Applications.galerie

Rev

Blame | Last modification | View Log | RSS feed

<?php
    
if($_GET['img'] == "")
exit;
        
$_image_ = urldecode( $_GET['img'] );

$_width_min_ = intval($_GET['width']);
$_height_min_ = intval($_GET['height']);
$_quality_ = intval($_GET['quality']);

$new_w = $_width_min_;
$imagedata = getimagesize($_image_);

if(!$imagedata[0])
exit();

$new_h = (int)($imagedata[1]*($new_w/$imagedata[0]));

if(($_height_min_) AND ($new_h > $_height_min_)) {
        $new_h = $_height_min_;
        $new_w = (int)($imagedata[0]*($new_h/$imagedata[1]));
}

if(strtolower(substr($_image_,-3)) == "jpg") {
  header("Content-type: image/jpg");
  $dst_img=ImageCreate($new_w,$new_h);
  $src_img=ImageCreateFromJpeg($_image_);
  $dst_img = imagecreatetruecolor($new_w, $new_h);
  imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
  $img = Imagejpeg($dst_img, '', $_quality_);
}

if(substr($_GET['img'],-3) == "gif") {
  header("Content-type: image/gif");
  $dst_img=ImageCreate($new_w,$new_h);
  $src_img=ImageCreateFromGif($_image_);  
  ImagePaletteCopy($dst_img,$src_img);
  ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
  $img = Imagegif($dst_img,'', $_quality_);
}

if(substr($_GET['img'],-3) == "png") {
  header("Content-type: image/png");
  $dst_img=ImageCreate($new_w,$new_h);
  $src_img=ImageCreateFromPng($_image_);  
  ImagePaletteCopy($dst_img,$src_img);
  ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
  $img = Imagepng($dst_img,'', $_quality_);
}

?>