When sending screenshots in an unknown format (txt, gif, etc.) the user is warned

and the screenshot is not added
This commit is contained in:
Jonathan Ernst
2005-02-24 04:48:42 +00:00
committed by WineHQ
parent 3b4eb09e1f
commit db7ed9bc5a
2 changed files with 31 additions and 10 deletions

View File

@@ -16,7 +16,7 @@ class Image {
/** /**
* Constructor: * Constructor:
* $file is the full path to the image. $this->is_loaded() * $file is the full path to the image. $this->isLoaded()
* should really be checked after making a new object. * should really be checked after making a new object.
*/ */
function Image($sRelativePath) function Image($sRelativePath)
@@ -58,12 +58,12 @@ class Image {
} }
/** /**
* is_loaded() * isLoaded()
* This function should always be checked after loading a file * This function should always be checked after loading a file
* with the constructor. Rteturns true if the image has been * with the constructor. Rteturns true if the image has been
* succesfully loaded. * succesfully loaded.
*/ */
function is_loaded() function isLoaded()
{ {
if($this->width > 0 AND $this->height > 0) if($this->width > 0 AND $this->height > 0)
return true; return true;

View File

@@ -45,7 +45,7 @@ class Screenshot {
$this->iAppId = $oRow->appId; $this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId; $this->iVersionId = $oRow->versionId;
$this->sUrl = $oRow->url; $this->sUrl = $oRow->url;
$this->bQueued = $oRow->queued; $this->bQueued = ($oRow->queued=="true")?true:false;
$this->sSubmitTime = $oRow->submitTime; $this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId; $this->iSubmitterId = $oRow->submitterId;
} }
@@ -92,12 +92,23 @@ class Screenshot {
} else // we managed to copy the file, now we have to process the image } else // we managed to copy the file, now we have to process the image
{ {
$this->sUrl = $this->iScreenshotId; $this->sUrl = $this->iScreenshotId;
$this->generate(); if($this->generate())
{
// we have to update the entry now that we know its name // we have to update the entry now that we know its name
$sQuery = "UPDATE appData $sQuery = "UPDATE appData
SET url = '".$this->iScreenshotId."' SET url = '".$this->iScreenshotId."'
WHERE id = '".$this->iScreenshotId."'"; WHERE id = '".$this->iScreenshotId."'";
if (!query_appdb($sQuery)) return false; if (!query_appdb($sQuery)) return false;
} else
{
addmsg("Unable to generate image or thumbnail. The file format might not be recognized. Please use PNG or JPEG only.","red");
$sQuery = "DELETE
FROM appData
WHERE id = '".$this->iScreenshotId."'";
query_appdb($sQuery);
return false;
}
} }
$this->screenshot($this->iScreenshotId,$this->bQueued); $this->screenshot($this->iScreenshotId,$this->bQueued);
@@ -182,6 +193,7 @@ class Screenshot {
/** /**
* This method generates a watermarked screenshot and thumbnail from the original file. * This method generates a watermarked screenshot and thumbnail from the original file.
* Usefull when changing thumbnail, upgrading GD, adding an image, etc. * Usefull when changing thumbnail, upgrading GD, adding an image, etc.
* Return false if an image could not be loaded.
*/ */
function generate() function generate()
{ {
@@ -189,6 +201,11 @@ class Screenshot {
// first we will create the thumbnail // first we will create the thumbnail
// load the screenshot // load the screenshot
$this->oThumbnailImage = new Image("/data/screenshots/originals/".$this->sUrl); $this->oThumbnailImage = new Image("/data/screenshots/originals/".$this->sUrl);
if(!$this->oThumbnailImage->isLoaded())
{
$this->oThumbnailImage->delete(); // if we cannot load the original file we delete it from the filesystem
return false;
}
$this->oThumbnailImage->make_thumb(0,0,1,'#000000'); $this->oThumbnailImage->make_thumb(0,0,1,'#000000');
// store the image // store the image
$this->oThumbnailImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/thumbnails/".$this->sUrl); $this->oThumbnailImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/thumbnails/".$this->sUrl);
@@ -196,17 +213,21 @@ class Screenshot {
// now we'll process the screenshot image for watermarking // now we'll process the screenshot image for watermarking
// load the screenshot // load the screenshot
$this->oScreenshotImage = new Image("/data/screenshots/originals/".$this->sUrl); $this->oScreenshotImage = new Image("/data/screenshots/originals/".$this->sUrl);
if(!$this->oScreenshotImage->isLoaded()) return false;
// resize the image // resize the image
$this->oScreenshotImage->make_full(); $this->oScreenshotImage->make_full();
// store the resized image // store the resized image
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/".$this->sUrl); $this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/".$this->sUrl);
// reload the resized screenshot // reload the resized screenshot
$this->oScreenshotImage = new Image("/data/screenshots/".$this->sUrl); $this->oScreenshotImage = new Image("/data/screenshots/".$this->sUrl);
if(!$this->oScreenshotImage->isLoaded()) return false;
// add the watermark to the screenshot // add the watermark to the screenshot
$this->oScreenshotImage->add_watermark($watermark->get_image_resource()); $this->oScreenshotImage->add_watermark($watermark->get_image_resource());
// store the watermarked image // store the watermarked image
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/".$this->sUrl); $this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/".$this->sUrl);
return true;
} }