2004-12-12 03:51:51 +00:00
|
|
|
<?php
|
|
|
|
|
/*************************************************************/
|
|
|
|
|
/* app image handler */
|
|
|
|
|
/* */
|
|
|
|
|
/* valid arguments: */
|
|
|
|
|
/* */
|
|
|
|
|
/* appId (required) */
|
|
|
|
|
/* versionId */
|
|
|
|
|
/* */
|
|
|
|
|
/* imageId (no appId required if this is specified) */
|
|
|
|
|
/* */
|
|
|
|
|
/* width */
|
|
|
|
|
/* height */
|
|
|
|
|
/* */
|
|
|
|
|
/* When both width/height are specified, the image is scaled */
|
|
|
|
|
/*************************************************************/
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
include("path.php");
|
|
|
|
|
require(BASE."include/"."incl.php");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handle_error($text)
|
|
|
|
|
{
|
|
|
|
|
echo $text;
|
|
|
|
|
// output image with the text, or something
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-24 15:49:39 +00:00
|
|
|
$appId = $_GET['appid'];
|
|
|
|
|
$imageId = $_GET['imageId'];
|
|
|
|
|
$versionId = $_GET['versionId'];
|
|
|
|
|
$width = $_GET['width'];
|
|
|
|
|
$height = $_GET['height'];
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
if(!$versionId) {
|
|
|
|
|
$versionId = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opendb();
|
|
|
|
|
|
2004-03-25 16:23:42 +00:00
|
|
|
// We have input, but wrong input
|
|
|
|
|
if( ( $width AND !is_numeric($width) ) || ( $height AND !is_numeric($height) ) )
|
|
|
|
|
{
|
2004-12-12 03:51:51 +00:00
|
|
|
$width = 100;
|
|
|
|
|
$height = 75;
|
2004-03-25 16:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-24 15:49:39 +00:00
|
|
|
if($imageId AND is_numeric($imageId) )
|
2005-01-10 22:24:15 +00:00
|
|
|
$result = query_appdb("SELECT * FROM appData WHERE id = $imageId");
|
2004-03-24 15:49:39 +00:00
|
|
|
|
|
|
|
|
else if($appId AND $versionId AND is_numeric($appId) AND is_numeric($versionId) )
|
2005-01-10 22:24:15 +00:00
|
|
|
$result = query_appdb("SELECT * FROM appData WHERE appId = $appId AND ".
|
2004-12-12 03:51:51 +00:00
|
|
|
"versionId = $versionId AND type = 'image' LIMIT 1");
|
2004-03-24 15:49:39 +00:00
|
|
|
else
|
|
|
|
|
handle_error("IDs wrong");
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
if(mysql_num_rows($result) == 0)
|
|
|
|
|
handle_error("No image found");
|
|
|
|
|
|
|
|
|
|
$ob = mysql_fetch_object($result);
|
|
|
|
|
|
|
|
|
|
// atm assumes the image is in png format
|
|
|
|
|
|
|
|
|
|
if(!ereg("/", $ob->url))
|
|
|
|
|
$url = "data/screenshots/$ob->url";
|
|
|
|
|
else
|
|
|
|
|
$url = $ob->url;
|
|
|
|
|
|
2004-03-24 15:49:39 +00:00
|
|
|
$imageInfo = getimagesize($url);
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-03-24 15:49:39 +00:00
|
|
|
if( $imageInfo[2] == 2 )
|
|
|
|
|
{
|
|
|
|
|
$type = 'jpeg';
|
|
|
|
|
$im = imagecreatefromjpeg($url);
|
|
|
|
|
}
|
|
|
|
|
else if( $imageInfo[2] == 3 )
|
|
|
|
|
{
|
|
|
|
|
$type = 'png';
|
|
|
|
|
$im = imagecreatefrompng($url);
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
else
|
2004-03-24 15:49:39 +00:00
|
|
|
handle_error("Unhandeled image type");
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-03-24 15:49:39 +00:00
|
|
|
if( !$imageInfo || !$im)
|
|
|
|
|
handle_error("Error handeling file.");
|
2004-03-15 16:22:00 +00:00
|
|
|
|
2004-03-24 15:49:39 +00:00
|
|
|
if($width && $height)
|
|
|
|
|
{
|
2004-03-15 16:22:00 +00:00
|
|
|
// do scaling
|
|
|
|
|
$sim = ImageCreate($width, $height);
|
|
|
|
|
ImageCopyResized($sim, $im, 0, 0, 0, 0, $width, $height, ImageSX($im), ImageSY($im));
|
|
|
|
|
}
|
2004-03-25 16:23:42 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// display full image
|
|
|
|
|
$sim = $im;
|
|
|
|
|
}
|
2004-03-15 16:22:00 +00:00
|
|
|
|
|
|
|
|
// output the image
|
|
|
|
|
if($type == "png")
|
|
|
|
|
{
|
|
|
|
|
header("Content-type: image/png");
|
2004-03-24 15:49:39 +00:00
|
|
|
ImagePNG($sim);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if($type == "jpeg")
|
|
|
|
|
{
|
|
|
|
|
header("Content-type: image/jpeg");
|
2004-03-24 15:49:39 +00:00
|
|
|
ImageJPEG($sim);
|
2004-03-15 16:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-03-24 15:49:39 +00:00
|
|
|
// Clear the memory
|
|
|
|
|
imagedestroy($im);
|
|
|
|
|
imagedestroy($sim);
|
2004-03-15 16:22:00 +00:00
|
|
|
?>
|