CC-3092: Station Information: not able to upload logo
- Adding a return statement fixed it...I don't what was I thinking... - Some indention seems messed up, fixed it
This commit is contained in:
parent
72553a257d
commit
8766cade49
1 changed files with 24 additions and 24 deletions
|
@ -1,42 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Zend_Filter_ImageSize implements Zend_Filter_Interface {
|
class Zend_Filter_ImageSize implements Zend_Filter_Interface {
|
||||||
|
public function filter($value) {
|
||||||
public function filter($value) {
|
if (!file_exists($value)) {
|
||||||
if(!file_exists($value)) {
|
|
||||||
throw new Zend_Filter_Exception('Image does not exist: ' . $value);
|
throw new Zend_Filter_Exception('Image does not exist: ' . $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$image = imageCreateFromString(file_get_contents($value));
|
$image = imageCreateFromString(file_get_contents($value));
|
||||||
if(false === $image) {
|
if (false === $image) {
|
||||||
throw new Zend_Filter_Exception('Can\'t load image: ' . $value);
|
throw new Zend_Filter_Exception('Can\'t load image: ' . $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find ratio to scale down to
|
// find ratio to scale down to
|
||||||
// TODO: pass 600 as parameter in the future
|
// TODO: pass 600 as parameter in the future
|
||||||
$origWidth = imagesx($image);
|
$origWidth = imagesx($image);
|
||||||
$origHeight = imagesy($image);
|
$origHeight = imagesy($image);
|
||||||
$ratio = max($origWidth, $origHeight) / 600;
|
$ratio = max($origWidth, $origHeight) / 600;
|
||||||
if($ratio < 1) {
|
|
||||||
return;
|
if ($ratio > 1) {
|
||||||
|
// img too big! create a scaled down image
|
||||||
|
$newWidth = round($origWidth / $ratio);
|
||||||
|
$newHeight = round($origHeight / $ratio);
|
||||||
|
$resized = imagecreatetruecolor($newWidth, $newHeight);
|
||||||
|
imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight);
|
||||||
|
|
||||||
|
// determine type and store to disk
|
||||||
|
$explodeResult = explode(".", $value);
|
||||||
|
$type = strtolower($explodeResult[count($explodeResult) - 1]);
|
||||||
|
$writeFunc = 'image' . $type;
|
||||||
|
if ($type == 'jpeg' || $type == 'jpg') {
|
||||||
|
imagejpeg($resized, $value, 100);
|
||||||
|
} else {
|
||||||
|
$writeFunc($resized, $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a scaled down image
|
return $value;
|
||||||
$newWidth = round($origWidth / $ratio);
|
}
|
||||||
$newHeight = round($origHeight / $ratio);
|
|
||||||
$resized = imagecreatetruecolor($newWidth, $newHeight);
|
|
||||||
imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight);
|
|
||||||
|
|
||||||
// determine type and store to disk
|
|
||||||
$explodeResult = explode(".", $value);
|
|
||||||
$type = $explodeResult[count($explodeResult) - 1];
|
|
||||||
$writeFunc = 'image' . $type;
|
|
||||||
if($type == 'jpeg' || $type == 'jpg') {
|
|
||||||
imagejpeg($resized, $value, 100);
|
|
||||||
} else {
|
|
||||||
$writeFunc($resized, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue