CC-2966: Remove minimum and maximum logo sizes - make them recommended instead

Fixed by:
1. change wording
2. attach custom filter to the logo upload form, the filter scales down the image
if it's larger than 600x600
This commit is contained in:
Yuchen Wang 2011-11-09 15:35:14 -05:00
parent 04bcc28b5e
commit 8f75bf1870
5 changed files with 52 additions and 14 deletions

View File

@ -1,5 +1,7 @@
<?php
require_once 'customfilters/ImageSize.php';
class Application_Form_RegisterAirtime extends Zend_Form
{
@ -102,12 +104,8 @@ class Application_Form_RegisterAirtime extends Zend_Form
->setRequired(false)
->setDecorators(array('File'))
->addValidator('Count', false, 1)
->addValidator('Extension', false, 'jpg,png,gif')
->addValidator('ImageSize', false, array(
'minwidth' => 200,
'minheight' => 200,
'maxwidth' => 600,
'maxheight' => 600));
->addValidator('Extension', false, 'jpg,jpeg,png,gif')
->addFilter('ImageSize');
$this->addElement($upload);
//enable support feedback

View File

@ -1,5 +1,7 @@
<?php
require_once 'customfilters/ImageSize.php';
class Application_Form_SupportSettings extends Zend_Form
{
@ -99,12 +101,8 @@ class Application_Form_SupportSettings extends Zend_Form
->setRequired(false)
->setDecorators(array('File'))
->addValidator('Count', false, 1)
->addValidator('Extension', false, 'jpg,png,gif')
->addValidator('ImageSize', false, array(
'minwidth' => 200,
'minheight' => 200,
'maxwidth' => 600,
'maxheight' => 600));
->addValidator('Extension', false, 'jpg,jpeg,png,gif')
->addFilter('ImageSize');
$upload->setAttrib('accept', 'image/jpeg,image/gif,image/png,image/jpg');
$this->addElement($upload);

View File

@ -0,0 +1,42 @@
<?php
class Zend_Filter_ImageSize implements Zend_Filter_Interface {
public function filter($value) {
if(!file_exists($value)) {
throw new Zend_Filter_Exception('Image does not exist: ' . $value);
}
$image = imageCreateFromString(file_get_contents($value));
if(false === $image) {
throw new Zend_Filter_Exception('Can\'t load image: ' . $value);
}
// find ratio to scale down to
// TODO: pass 600 as parameter in the future
$origWidth = imagesx($image);
$origHeight = imagesy($image);
$ratio = max($origWidth, $origHeight) / 600;
if($ratio < 1) {
return;
}
// 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 = $explodeResult[count($explodeResult) - 1];
$writeFunc = 'image' . $type;
if($type == 'jpeg' || $type == 'jpg') {
imagejpeg($resized, $value, 100);
} else {
$writeFunc($resized, $value);
}
}
}
?>

View File

@ -144,7 +144,7 @@
<?php }?>
<?php echo $this->element->getElement('Logo') ?>
<p class="info-text">Min. size: 200x200 Max. size: 600x600</p>
<p class="info-text">Note: Anything larger than 600x600 will be resized.</p>
<?php if($this->element->getElement('Logo')->hasErrors()) : ?>
<ul class='errors'>
<?php foreach($this->element->getElement('Logo')->getMessages() as $error): ?>

View File

@ -138,7 +138,7 @@
<?php }?>
<?php echo $this->element->getElement('Logo') ?>
<div class="info-text"><p>Min. size: 200x200 Max. size: 600x600</p></div>
<div class="info-text"><p>Note: Anything larger than 600x600 will be resized.</p></div>
<?php if($this->element->getElement('Logo')->hasErrors()) : ?>
<ul class='errors'>
<?php foreach($this->element->getElement('Logo')->getMessages() as $error): ?>