I have a form with upload image field. How to resize the recently uploaded image to desired size?
My current form is :
<?php
class Application_Form_User extends Zend_Form
{
public function init()
{
$this->setAttrib('enctype', 'multipart/form-data');
$this->setAction("");
$this->setMethod("post");
$element = new Zend_Form_Element_File('photo');
$element->setLabel('Upload an image:')
->setValueDisabled(true);
$this->addElement($element, 'photo');
$element->addValidator('Count', false, 1);
// limit to 1000K
$element->addValidator('Size', false, 1024000);
// only JPEG, PNG, and GIFs
$element->addValidator('Extension', false, 'jpg,png,gif');
$submit = $this->createElement('submit', 'submit');
$submit->setLabel('Save');
$this->addElement($submit);
}
}
And my controller:
public function indexAction()
{
$form=new Application_Form_User();
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$file=pathinfo($form->photo->getFileName());
$form->photo->addFilter('Rename', PUBLIC_PATH.'/images/'.uniqid().time().'.'.$file['extension']);
if ($form->photo->receive()) {
$this->view->photo=pathinfo($form->photo->getFileName());
}
}
}
$this->view->form=$form;
}
Can somebody provide me with an example? How can i use plugins like php thumbnailer or similar plugin to resize the uploaded image?
Skoch_Filter_File_Resize works. It is a custom filter: http://eliteinformatiker.de/2011/09/02/thumbnails-upload-and-resize-images-with-zend_form_element_file/