/** Build html and return it * * @param array $imagedata */ public function buildHtml($imagedata) { $image = ''; foreach ($imagedata as $data) { if (!is_null($data['i'])) { $file = './images/thumbnails/' . $data['i'] . '.jpg'; if (file_exists($file)) { list($w, $h, $type, $attr) = getimagesize($file); $image .= '<a href="/' . $data['imagedir'] . 'medium/' . strtolower($data['f']) . '" rel="lightbox" title="Medium sized image of: ' . $data['old_findID'] . ' a ' . $data['broadperiod'] . ' ' . $data['objecttype'] . '"><img src="' . $this->view->baseUrl() . '/images/thumbnails/' . $data['i'] . '.jpg" class="tmb" width="' . $w . '" height="' . $h . '" alt="' . ucfirst($data['objecttype']) . '" rel="license" resource="http://creativecommons.org/licenses/by/2.0/"/></a>'; echo $image; } elseif (!file_exists($file)) { $location = './' . $data['imagedir'] . $data['f']; $phMagick = new phMagick($location, $file); $phMagick->resize(100, 0); $phMagick->convert(); } else { echo '<p>Image unavailable.</p>'; } } } }
/** Change staff profile image */ public function logoAction() { $contacts = new Contacts(); $people = $contacts->fetchRow($contacts->select()->where('dbaseID = ?', $this->getIdentityForForms())); $inst = $people->identifier; $this->view->inst = $inst; $logos = new InstLogos(); $logoslisted = $logos->getLogosInst($inst); $this->view->logos = $logoslisted; $form = new AddStaffLogoForm(); $form->details->setLegend('Add a logo: '); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $upload = new Zend_File_Transfer_Adapter_Http(); $upload->addValidator('NotExists', true, array(self::LOGOPATH)); if ($upload->isValid()) { $filename = $form->getValue('logo'); $largepath = self::LOGOPATH; $original = $largepath . $filename; $name = substr($filename, 0, strrpos($filename, '.')); $ext = '.jpg'; $converted = $name . $ext; $insertData = array(); $insertData['image'] = $converted; $insertData['instID'] = $inst; $insertData['created'] = $this->getTimeForForms(); $insertData['createdBy'] = $this->getIdentityForForms(); foreach ($insertData as $key => $value) { if (is_null($value) || $value == "") { unset($insertData[$key]); } } $replace = $form->getValue('replace'); if ($replace == 1) { foreach ($logoslisted as $l) { unlink(self::LOGOPATH . 'thumbnails/' . $l['image']); unlink(self::LOGOPATH . $l['image']); unlink(self::LOGOPATH . 'resized/' . $l['image']); } } $smallpath = self::LOGOPATH . 'thumbnails/' . $converted; $mediumpath = self::LOGOPATH . 'resized/' . $converted; //create medium size $phMagick = new phMagick($original, $mediumpath); $phMagick->resize(300, 0); $phMagick->convert(); $phMagick = new phMagick($original, $smallpath); $phMagick->resize(100, 0); $phMagick->convert(); $logos->insert($insertData); $upload->receive(); $this->getFlash()->addMessage('The image has been resized and zoomified!'); $this->redirect('/users/account/'); } else { $this->getFlash()->addMessage('There is a problem with your upload. Probably that image exists.'); $this->view->errors = $upload->getMessages(); } } else { $form->populate($formData); $this->getFlash()->addMessage('Check your form for errors'); } } }
/** Edit a specific image */ public function editAction() { if ($this->_getParam('id', 0)) { $form = new ImageEditForm(); $form->submit->setLabel('Update image..'); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $updateData = array(); $updateData['label'] = $form->getValue('label'); $updateData['imagerights'] = $form->getValue('imagerights'); $updateData['county'] = $form->getValue('county'); $updateData['period'] = $form->getValue('period'); $updateData['updated'] = $this->getTimeForForms(); $updateData['updatedBy'] = $this->getIdentityForForms(); foreach ($updateData as $key => $value) { if (is_null($value) || $value == "") { unset($updateData[$key]); } } $where = $this->_images->getAdapter()->quoteInto('imageID = ?', $this->_getParam('id')); $rotate = $form->getValue('rotate'); $filename = $form->getValue('filename'); $imagedir = $form->getValue('imagedir'); $regenerate = $form->getValue('regenerate'); $path = './' . $imagedir . $filename; $largepath = './' . $imagedir; $mediumpath = './' . $imagedir . 'medium/'; $smallpath = './' . $imagedir . 'small/'; $displaypath = './' . $imagedir . 'display/'; $thumbpath = self::PATH . 'thumbnails/'; $id = $this->_getParam('id'); $name = substr($filename, 0, strrpos($filename, '.')); $ext = '.jpg'; if (isset($rotate)) { //rotate original $phMagickOriginal = new phMagick($largepath . $filename, $largepath . $filename); $phMagickOriginal->rotate($rotate); //rotate image for medium if (file_exists($mediumpath . $name . $ext)) { $phMagickMedium = new phMagick($mediumpath . $name . $ext, $mediumpath . $name . $ext); $phMagickMedium->rotate($rotate); // Zend_Debug::dump($phMagickMedium); } else { $phMagickMediumCreate = new phMagick($largepath . $filename, $mediumpath . $name . $ext); $phMagickMediumCreate->resize(500, 0); $phMagickMediumCreate->rotate($rotate); $phMagickMediumCreate->convert(); // Zend_Debug::dump($phMagickMediumCreate); } //rotate small image if (file_exists($smallpath . $name . $ext)) { $phMagickSmall = new phMagick($smallpath . $name . $ext, $smallpath . $name . $ext); $phMagickSmall->rotate($rotate); //Zend_Debug::dump($phMagickSmall); } else { $phMagickSmallCreate = new phMagick($largepath . $filename, $smallpath . $name . $ext); $phMagickSmallCreate->resize(40, 0); $phMagickSmallCreate->rotate($rotate); $phMagickSmallCreate->convert(); //Zend_Debug::dump($phMagickSmallCreate); } //rotate display image if (file_exists($displaypath . $name . $ext)) { $phMagickDisplay = new phMagick($displaypath . $name . $ext, $displaypath . $name . $ext); $phMagickDisplay->rotate($rotate); // Zend_Debug::dump($phMagickDisplay); } else { $phMagickDisplayCreate = new phMagick($largepath . $name . $ext, $displaypath . $name . $ext); $phMagickDisplayCreate->resize(0, 150); $phMagickDisplayCreate->rotate($rotate); $phMagickDisplayCreate->convert(); //Zend_Debug::dump($phMagickDisplayCreate); } //rotate thumbnail if (file_exists($thumbpath . $id . '.jpg')) { $phMagickThumb = new phMagick($thumbpath . $id . '.jpg', $thumbpath . $id . '.jpg'); $phMagickThumb->rotate($rotate); //Zend_Debug::dump($phMagickThumb); } else { $thumbpath = self::PATH . 'thumbnails/'; $originalpath = $path; $phMagickRegen = new phMagick($originalpath, $thumbpath . $id . '.jpg'); $phMagickRegen->resize(100, 0); $phMagickRegen->convert(); } } if (isset($regenerate)) { $thumbpath = self::PATH . 'thumbnails/'; $originalpath = $path; $phMagickRegen = new phMagick($originalpath, $thumbpath . $id . '.jpg'); $phMagickRegen->resize(100, 0); $phMagickRegen->convert(); } $update = $this->_images->update($updateData, $where); //Update the solr instance $this->_helper->solrUpdater->update('beoimages', $this->_getParam('id')); $this->_helper->cache->remove('findtoimage' . $this->_getParam('id')); $this->_flashMessenger->addMessage('Image and metadata updated!'); $this->_redirect(self::REDIRECT . 'image/id/' . $this->_getParam('id')); } else { $form->populate($form->getValues()); } } else { $id = (int) $this->_request->getParam('id', 0); if ($id > 0) { $image = $this->_images->getImage($id); $form->populate($image['0']); } } } else { throw new Exception($this->_missingParameter); } }
/** * invert * @author Cornelius Hansjakob <*****@*****.**> * @version 1.0 */ public function invert() { parent::invertColors(); }
/** Give them a logo */ public function logoAction() { $form = new AddStaffLogoForm(); $form->details->setLegend('Add a logo: '); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $upload = new Zend_File_Transfer_Adapter_Http(); $upload->addValidator('NotExists', true, array(self::LOGOPATH)); if ($upload->isValid()) { $filename = $form->getValue('image'); $insertData = array(); $insertData['host'] = $filename; $insertData['updated'] = $this->getTimeForForms(); $insertData['updatedBy'] = $this->getIdentityForForms(); foreach ($insertData as $key => $value) { if (is_null($value) || $value == "") { unset($insertData[$key]); } } $original = self::LOGOPATH . $filename; $name = substr($filename, 0, strrpos($filename, '.')); $ext = '.jpg'; $converted = $name . $ext; $smallpath = self::LOGOPATH . 'thumbnails/' . $converted; $mediumpath = self::LOGOPATH . 'resized/' . $converted; //create medium size $phMagick = new phMagick($original, $mediumpath); $phMagick->resize(300, 0); $phMagick->convert(); /* Zend_Debug::dump($convertsmall); Zend_Debug::dump($phMagick); exit; */ $phMagick = new phMagick($original, $smallpath); $phMagick->resize(100, 0); $phMagick->convert(); $regions = new StaffRegions(); $where = array(); $where[] = $regions->getAdapter()->quoteInto('id = ?', $this->_getParam('id')); $regions->update($insertData, $where); $upload->receive(); $this->_flashMessenger->addMessage('The image has been resized and zoomified!'); $this->_redirect('/admin/contacts/institution/id/' . $this->_getParam('id')); } else { $this->_flashMessenger->addMessage('There is a problem with your upload. Probably that image exists.'); $this->view->errors = $upload->getMessages(); } } else { $form->populate($formData); $this->_flashMessenger->addMessage('Check your form for errors'); } } }
/** * Create all the normalized sizes for the Image. Called by postSave(). */ public function make_sizes() { if (!isset($this->_set_image)) { Carper::croak("image not set for " . $this->img_uuid); } $dir = self::get_directory($this->img_ref_type, $this->img_uuid); $ext = self::$CONFIG[$this->img_ref_type]['convert_to']; $name = self::$CONFIG[$this->img_ref_type]['filename']; // remove old files, and copy a new one array_map("unlink", glob("{$dir}/*")); $fname = $this->img_file_name; copy($this->_set_image, "{$dir}{$fname}"); // convert at full resolution $p = new phMagick($this->_set_image, "{$dir}{$name}.{$ext}"); $p->convert(); // resized versions foreach (self::$CONFIG[$this->img_ref_type]['sizes'] as $size => $dim) { $p = new phMagick($this->_set_image, "{$dir}{$name}_{$size}.{$ext}"); if ($dim[0] == 0 || $dim[1] == 0) { $p->resize($dim[0], $dim[1]); } elseif (is_a($this, 'ImageOrgLogo')) { $p->resize($dim[0], $dim[1]); } else { $p->resizeExactly($dim[0], $dim[1]); } } $this->_set_image = false; }