aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Image/Gd/Thumbnail.php
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2012-02-18 00:07:50 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2012-02-18 00:07:50 +0000
commit14691cd854be3e9ee272c9619a6368c83d72267b (patch)
tree89215d53db8d6f01bb24a5c1d30d9dd4c8d7a5b9 /h-source/Library/Image/Gd/Thumbnail.php
parenta2c0b2c4f80463a94e2dd87b59f193ab3aa925eb (diff)
upload new EasyGiant library and added added a new filter for the model name (part 2)
Diffstat (limited to 'h-source/Library/Image/Gd/Thumbnail.php')
-rw-r--r--h-source/Library/Image/Gd/Thumbnail.php70
1 files changed, 53 insertions, 17 deletions
diff --git a/h-source/Library/Image/Gd/Thumbnail.php b/h-source/Library/Image/Gd/Thumbnail.php
index 137c287..22e501e 100644
--- a/h-source/Library/Image/Gd/Thumbnail.php
+++ b/h-source/Library/Image/Gd/Thumbnail.php
@@ -38,14 +38,15 @@ class Image_Gd_Thumbnail
$this->basePath = $basePath;
$defaultParams = array(
- 'imgWidth' => 100,
- 'imgHeight' => 100,
+ 'imgWidth' => null,
+ 'imgHeight' => null,
'defaultImage' => null,
'cropImage' => 'no',
'horizAlign' => 'left',
'vertAlign' => 'top',
'resample' => 'yes',
'function' => 'none',
+ 'outputFormat' => 'jpeg',
);
//set the $this->scaffold->params array
@@ -61,28 +62,45 @@ class Image_Gd_Thumbnail
//create the thumbnail
//$imageName: the name of the file inside $this->basePath
- public function render($imageFile)
+ //$outputFile: the name of the output file
+ public function render($imageFile, $outputFile = null)
{
$imagePath = $this->basePath . basename($imageFile);
if (!file_exists($imagePath) and isset($this->params['defaultImage'])) $imagePath = $this->params['defaultImage'];
-
+
$img = null;
- $ext = strtolower(end(explode('.', $imagePath)));
+ $type = 'jpeg';
+ $contentType = 'image/jpeg';
- if (strcmp($ext,'jpg') === 0 or strcmp($ext,'jpeg') === 0) {
- $img = @imagecreatefromjpeg($imagePath);
- } else if (strcmp($ext,'png') === 0) {
- $img = @imagecreatefrompng($imagePath);
- } else if (strcmp($ext,'gif') === 0) {
- $img = @imagecreatefromgif($imagePath);
+ if (file_exists($imagePath))
+ {
+ $ext = strtolower(end(explode('.', $imagePath)));
+
+ if (strcmp($ext,'jpg') === 0 or strcmp($ext,'jpeg') === 0) {
+ $img = @imagecreatefromjpeg($imagePath);
+ $type = 'jpeg';
+ $contentType = 'image/jpeg';
+ } else if (strcmp($ext,'png') === 0) {
+ $img = @imagecreatefrompng($imagePath);
+ $type = 'png';
+ $contentType = 'image/png';
+ } else if (strcmp($ext,'gif') === 0) {
+ $img = @imagecreatefromgif($imagePath);
+ $type = 'gif';
+ $contentType = 'image/gif';
+ }
}
//If an image was successfully loaded, test the image for size
- if ($img) {
+ if ($img)
+ {
//image size
$width = imagesx($img);
$height = imagesy($img);
+
+ if (!isset($this->params['imgWidth'])) $this->params['imgWidth'] = $width;
+ if (!isset($this->params['imgHeight'])) $this->params['imgHeight'] = $height;
if ($this->params['cropImage'] === 'no')
{
@@ -92,7 +110,7 @@ class Image_Gd_Thumbnail
{
$scale = max($this->params['imgWidth']/$width, $this->params['imgHeight']/$height);
}
-
+
if ($scale < 1) {
$xSrc = 0;
@@ -170,15 +188,33 @@ class Image_Gd_Thumbnail
}
- if (!$img) {
- $img = imagecreate($this->params['imgWidth'], $this->params['imgHeight']);
+ if (!$img)
+ {
+ $imgWidth = isset($this->params['imgWidth']) ? $this->params['imgWidth'] : 100;
+ $imgHeight = isset($this->params['imgHeight']) ? $this->params['imgHeight'] : 100;
+
+ $img = imagecreate($imgWidth, $imgHeight);
imagecolorallocate($img,200,200,200);
}
//print the image
- header("Content-type: image/jpeg");
- imagejpeg($img,null,90);
+ if (!isset($outputFile))
+ {
+ header("Content-type: $contentType");
+ }
+ if (strcmp($type,'png') === 0)
+ {
+ imagepng($img,$outputFile,9);
+ }
+ else if (strcmp($type,'gif') === 0)
+ {
+ imagegif($img,$outputFile);
+ }
+ else
+ {
+ imagejpeg($img,$outputFile,90);
+ }
}
} \ No newline at end of file