sorbetcms/classes/imgsize.php

69 lines
1.2 KiB
PHP
Executable File

<?php
if (!defined('entry')) {
define('entry', true);
}
$img = @$_GET['img'];
$w = @$_GET['w'];
$h = @$_GET['h'];
$x = getimagesize($img);
$sw = $x[0];
$sh = $x[1];
if (isset($w) and !isset($h)) {
$h = (100 / ($sw / $w)) * .01;
$h = @round($sh * $h);
} elseif (isset($h) and !isset($w)) {
$w = (100 / ($sh / $h)) * .01;
$w = @round($sw * $w);
}
$imgext = pathinfo($img, PATHINFO_EXTENSION);
switch ($imgext) {
case 'png':
header("Content-type: image/png");
$s_img = imagecreatefrompng($img);
break;
case 'jpg':
case 'jpeg':
header("Content-type: image/jpeg");
$s_img = imagecreatefromjpeg($img);
break;
case 'gif':
header("Content-type: image/gif");
$s_img = imagecreatefromgif($img);
break;
default:
readfile($img);
exit();
break;
}
$d_img = imagecreatetruecolor($w, $h);
$sw = imagesx($s_img);
$sh = imagesy($s_img);
$dw = imagesx($d_img);
$dh = imagesy($d_img);
imagecopyresampled($d_img, $s_img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
switch ($imgext) {
case 'png':
imagepng($d_img);
break;
case 'jpg':
case 'jpeg':
imagejpeg($d_img);
break;
case 'gif':
imagegif($d_img);
break;
default:
readfile($img);
exit();
break;
}