View file wapt_gall/wapt_gall/image.php

File size: 1.8Kb
<?php
$file_name=$_GET['file_name'];
$new_size=$_GET['new_size'];
$q=$_GET['q'];
$image_type=@GetImageSize("$file_name") or die('error....');
if($image_type[2] <> 1 && $image_type[2] <> 2 && $image_type[2] <> 3)die();
if($image_type[2] == 1){$type='gif';header('Content-type: image/gif');}
if($image_type[2] == 2){$type='jpeg';header('Content-type: image/jpeg');}
if($image_type[2] == 3){$type='png';header('Content-type: image/png');}
if($type =='gif'){
$old = imageCreateFromgif("$file_name");
$w = imageSX($old);
$h = imageSY($old);
if($w>$h){               
$w_new=$new_size;
$h_new=$new_size*($h/$w);
}
if($h>$w){
$w_new=$new_size*($w/$h);
$h_new=$new_size;
}
if($h==$w){
$w_new=$new_size;
$h_new=$new_size;
}
$new = imagecreatetruecolor($w_new, $h_new);
imageCopyResized($new, $old, 0, 0, 0, 0, $w_new, $h_new, $w, $h);
imagegif($new,"",$q);
imageDestroy($old);
imageDestroy($new);
}
if($type =='jpeg'){
$old = imageCreateFromjpeg("$file_name");
$w = imageSX($old);
$h = imageSY($old);
if($w>$h){
$w_new=$new_size;
$h_new=$new_size*($h/$w);
}
if($h>$w){
$w_new=$new_size*($w/$h);
$h_new=$new_size;
}
if($h==$w){
$w_new=$new_size;
$h_new=$new_size;
}
$new = imagecreatetruecolor($w_new, $h_new);
imageCopyResized($new, $old, 0, 0, 0, 0, $w_new, $h_new, $w, $h);
imageJpeg($new,"",$q);
imageDestroy($old);
imageDestroy($new);
}
if($type =='png'){
$old = imageCreateFrompng("$file_name");
$w = imageSX($old);
$h = imageSY($old);
if($w>$h){
$w_new=$new_size;
$h_new=$new_size*($h/$w);
}
if($h>$w){
$w_new=$new_size*($w/$h);
$h_new=$new_size;
}
if($h==$w){
$w_new=$new_size;
$h_new=$new_size;
}
$new = imagecreatetruecolor($w_new, $h_new);
imageCopyResized($new, $old, 0, 0, 0, 0, $w_new, $h_new, $w, $h);
imagepng($new,"",$q);
imageDestroy($old);
imageDestroy($new);
}
?>