This repository has been archived on 2025-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
qemudb/appimage.php

116 lines
2.8 KiB
PHP
Raw Normal View History

<?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;
}
$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();
// We have input, but wrong input
if( ( $width AND !is_numeric($width) ) || ( $height AND !is_numeric($height) ) )
{
$width = 100;
$height = 75;
}
if($imageId AND is_numeric($imageId) )
2004-03-15 16:22:00 +00:00
$result = mysql_query("SELECT * FROM appData WHERE id = $imageId");
else if($appId AND $versionId AND is_numeric($appId) AND is_numeric($versionId) )
2004-03-15 16:22:00 +00:00
$result = mysql_query("SELECT * FROM appData WHERE appId = $appId AND ".
"versionId = $versionId AND type = 'image' LIMIT 1");
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;
$imageInfo = getimagesize($url);
2004-03-15 16:22:00 +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
handle_error("Unhandeled image type");
2004-03-15 16:22:00 +00:00
if( !$imageInfo || !$im)
handle_error("Error handeling file.");
2004-03-15 16:22:00 +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));
}
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");
ImagePNG($sim);
2004-03-15 16:22:00 +00:00
}
else
if($type == "jpeg")
{
header("Content-type: image/jpeg");
ImageJPEG($sim);
2004-03-15 16:22:00 +00:00
}
// Clear the memory
imagedestroy($im);
imagedestroy($sim);
2004-03-15 16:22:00 +00:00
?>