Get imagetype from getimagesize(). Switched to $_GET. Clearing memory.
This commit is contained in:
committed by
Jeremy Newman
parent
461a3b5307
commit
5953434a6f
57
appimage.php
57
appimage.php
@@ -26,10 +26,11 @@ function handle_error($text)
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$appId && !$imageId) {
|
$appId = $_GET['appid'];
|
||||||
handle_error("No appId");
|
$imageId = $_GET['imageId'];
|
||||||
return;
|
$versionId = $_GET['versionId'];
|
||||||
}
|
$width = $_GET['width'];
|
||||||
|
$height = $_GET['height'];
|
||||||
|
|
||||||
if(!$versionId) {
|
if(!$versionId) {
|
||||||
$versionId = 0;
|
$versionId = 0;
|
||||||
@@ -37,11 +38,14 @@ if(!$versionId) {
|
|||||||
|
|
||||||
opendb();
|
opendb();
|
||||||
|
|
||||||
if($imageId)
|
if($imageId AND is_numeric($imageId) )
|
||||||
$result = mysql_query("SELECT * FROM appData WHERE id = $imageId");
|
$result = mysql_query("SELECT * FROM appData WHERE id = $imageId");
|
||||||
else
|
|
||||||
|
else if($appId AND $versionId AND is_numeric($appId) AND is_numeric($versionId) )
|
||||||
$result = mysql_query("SELECT * FROM appData WHERE appId = $appId AND ".
|
$result = mysql_query("SELECT * FROM appData WHERE appId = $appId AND ".
|
||||||
"versionId = $versionId AND type = 'image' LIMIT 1");
|
"versionId = $versionId AND type = 'image' LIMIT 1");
|
||||||
|
else
|
||||||
|
handle_error("IDs wrong");
|
||||||
|
|
||||||
if(mysql_num_rows($result) == 0)
|
if(mysql_num_rows($result) == 0)
|
||||||
handle_error("No image found");
|
handle_error("No image found");
|
||||||
@@ -55,42 +59,45 @@ if(!ereg("/", $ob->url))
|
|||||||
else
|
else
|
||||||
$url = $ob->url;
|
$url = $ob->url;
|
||||||
|
|
||||||
if(eregi(".+\\.(jpg|jpeg)$", $url))
|
$imageInfo = getimagesize($url);
|
||||||
$type = "jpeg";
|
|
||||||
|
if( $imageInfo[2] == 2 )
|
||||||
|
{
|
||||||
|
$type = 'jpeg';
|
||||||
|
$im = imagecreatefromjpeg($url);
|
||||||
|
}
|
||||||
|
else if( $imageInfo[2] == 3 )
|
||||||
|
{
|
||||||
|
$type = 'png';
|
||||||
|
$im = imagecreatefrompng($url);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
if(eregi(".+\\.(png)$", $url))
|
handle_error("Unhandeled image type");
|
||||||
$type = "png";
|
|
||||||
|
|
||||||
if(!$type)
|
if( !$imageInfo || !$im)
|
||||||
handle_error("Unknown Image Type");
|
handle_error("Error handeling file.");
|
||||||
|
|
||||||
if($type == "png")
|
if($width && $height)
|
||||||
$im = ImageCreateFromPNG($url);
|
{
|
||||||
else
|
|
||||||
if($type == "jpeg")
|
|
||||||
$im = ImageCreateFromJpeg($url);
|
|
||||||
|
|
||||||
if(!$im)
|
|
||||||
handle_error("Error");
|
|
||||||
|
|
||||||
if($width && $height) {
|
|
||||||
// do scaling
|
// do scaling
|
||||||
$sim = ImageCreate($width, $height);
|
$sim = ImageCreate($width, $height);
|
||||||
ImageCopyResized($sim, $im, 0, 0, 0, 0, $width, $height, ImageSX($im), ImageSY($im));
|
ImageCopyResized($sim, $im, 0, 0, 0, 0, $width, $height, ImageSX($im), ImageSY($im));
|
||||||
$im = $sim;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// output the image
|
// output the image
|
||||||
if($type == "png")
|
if($type == "png")
|
||||||
{
|
{
|
||||||
header("Content-type: image/png");
|
header("Content-type: image/png");
|
||||||
ImagePNG($im);
|
ImagePNG($sim);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if($type == "jpeg")
|
if($type == "jpeg")
|
||||||
{
|
{
|
||||||
header("Content-type: image/jpeg");
|
header("Content-type: image/jpeg");
|
||||||
ImageJPEG($im);
|
ImageJPEG($sim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the memory
|
||||||
|
imagedestroy($im);
|
||||||
|
imagedestroy($sim);
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user