<?php //resizeimage.php
//PHP script that resizes on the fly an image file $filename = $_REQUEST['image']; $size = $_REQUEST['size']; //Get the file's extension (e.g. jpg, gif, png) $ext = substr($filename, -3, 3);
if ($ext == 'jpg' || $ext == 'JPG')
{ //$percent = 0.10;
// Content type header('Content-type: image/jpeg');
// Get new sizes if ($size == 'small')
{
$width = 90;
$height = 47;
}
elseif ($size == 'medium')
{
$width = 221;
$height = 116;
}
list($width, $height) = getimagesize($filename);
if ($size == 'small')
{
$newwidth = 90;
$newheight = 47;
}
elseif ($size == 'medium')
{
$newwidth = 221;
$newheight = 116;
}
// Load $thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output imagejpeg($thumb);
}
elseif ($ext == 'gif' || $ext == 'GIF')
{ //$percent = 0.10;
// Content type header('Content-type: image/gif');
// Get new sizes if ($size == 'small')
{
$width = 90;
$height = 47;
}
elseif ($size == 'medium')
{
$width = 221;
$height = 116;
}
list($width, $height) = getimagesize($filename);
if ($size == 'small')
{
$newwidth = 90;
$newheight = 47;
}
elseif ($size == 'medium')
{
$newwidth = 221;
$newheight = 116;
}
// Load $thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromgif($filename);
// Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output imagegif($thumb);
}
elseif ($ext == 'png' || $ext=='PNG')
{ //$percent = 0.10;
// Content type header('Content-type: image/png');
// Get new sizes if ($size == 'small')
{
$width = 90;
$height = 47;
}
elseif ($size == 'medium')
{
$width = 221;
$height = 116;
}
list($width, $height) = getimagesize($filename);
if ($size == 'small')
{
$newwidth = 90;
$newheight = 47;
}
elseif ($size == 'medium')
{
$newwidth = 221;
$newheight = 116;
}
// Load $thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefrompng($filename);
// Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output imagepng($thumb);
}
?>
|
|