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:
parent
04bcc28b5e
commit
8f75bf1870
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once 'customfilters/ImageSize.php';
|
||||||
|
|
||||||
class Application_Form_RegisterAirtime extends Zend_Form
|
class Application_Form_RegisterAirtime extends Zend_Form
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -102,12 +104,8 @@ class Application_Form_RegisterAirtime extends Zend_Form
|
||||||
->setRequired(false)
|
->setRequired(false)
|
||||||
->setDecorators(array('File'))
|
->setDecorators(array('File'))
|
||||||
->addValidator('Count', false, 1)
|
->addValidator('Count', false, 1)
|
||||||
->addValidator('Extension', false, 'jpg,png,gif')
|
->addValidator('Extension', false, 'jpg,jpeg,png,gif')
|
||||||
->addValidator('ImageSize', false, array(
|
->addFilter('ImageSize');
|
||||||
'minwidth' => 200,
|
|
||||||
'minheight' => 200,
|
|
||||||
'maxwidth' => 600,
|
|
||||||
'maxheight' => 600));
|
|
||||||
$this->addElement($upload);
|
$this->addElement($upload);
|
||||||
|
|
||||||
//enable support feedback
|
//enable support feedback
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once 'customfilters/ImageSize.php';
|
||||||
|
|
||||||
class Application_Form_SupportSettings extends Zend_Form
|
class Application_Form_SupportSettings extends Zend_Form
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -99,12 +101,8 @@ class Application_Form_SupportSettings extends Zend_Form
|
||||||
->setRequired(false)
|
->setRequired(false)
|
||||||
->setDecorators(array('File'))
|
->setDecorators(array('File'))
|
||||||
->addValidator('Count', false, 1)
|
->addValidator('Count', false, 1)
|
||||||
->addValidator('Extension', false, 'jpg,png,gif')
|
->addValidator('Extension', false, 'jpg,jpeg,png,gif')
|
||||||
->addValidator('ImageSize', false, array(
|
->addFilter('ImageSize');
|
||||||
'minwidth' => 200,
|
|
||||||
'minheight' => 200,
|
|
||||||
'maxwidth' => 600,
|
|
||||||
'maxheight' => 600));
|
|
||||||
$upload->setAttrib('accept', 'image/jpeg,image/gif,image/png,image/jpg');
|
$upload->setAttrib('accept', 'image/jpeg,image/gif,image/png,image/jpg');
|
||||||
$this->addElement($upload);
|
$this->addElement($upload);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -144,7 +144,7 @@
|
||||||
<?php }?>
|
<?php }?>
|
||||||
|
|
||||||
<?php echo $this->element->getElement('Logo') ?>
|
<?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()) : ?>
|
<?php if($this->element->getElement('Logo')->hasErrors()) : ?>
|
||||||
<ul class='errors'>
|
<ul class='errors'>
|
||||||
<?php foreach($this->element->getElement('Logo')->getMessages() as $error): ?>
|
<?php foreach($this->element->getElement('Logo')->getMessages() as $error): ?>
|
||||||
|
|
|
@ -138,7 +138,7 @@
|
||||||
<?php }?>
|
<?php }?>
|
||||||
|
|
||||||
<?php echo $this->element->getElement('Logo') ?>
|
<?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()) : ?>
|
<?php if($this->element->getElement('Logo')->hasErrors()) : ?>
|
||||||
<ul class='errors'>
|
<ul class='errors'>
|
||||||
<?php foreach($this->element->getElement('Logo')->getMessages() as $error): ?>
|
<?php foreach($this->element->getElement('Logo')->getMessages() as $error): ?>
|
||||||
|
|
Loading…
Reference in New Issue