private function uploadAndResizeBanner() { $desktopFolder = 'images/banners/desktop'; $tabletFolder = 'images/banners/tablet'; $mobileFolder = 'images/banners/mobile'; $fileTypes = array('image/jpeg', 'image/jpg', 'image/pjpeg'); // instantialise the Upload class $upload = new Upload('banner_img', $fileTypes, $desktopFolder); $returnFile = $upload->isUploaded(); // if no file has been uploaded then display error exit as nothing to resize if (!$returnFile) { $result['image_error'] = $upload->msg; $result['resized'] = false; return $result; } // there is a file so resize, first set the file paths for all images $fileName = basename($returnFile); $desktopPath = $desktopFolder . '/' . $fileName; $tabletPath = $tabletFolder . '/' . $fileName; $mobilePath = $mobileFolder . '/' . $fileName; // copy file to all other folders folders copy($returnFile, $tabletPath); copy($returnFile, $mobilePath); // if copy fails then exit if (!file_exists($tabletPath) || !file_exists($mobilePath)) { return false; } $imgInfo = getimagesize($returnFile); // resize image to 960px by 290px for the desktop $resizePhoto = new ResizeImage($desktopPath, '', $desktopFolder, '960', '290'); // if the resize to 200px is unsuccessful if (!$resizePhoto->resize()) { // echo 'Unable to resize image to 960 pixels'; // (development only) } // resize image to 735px by 222px for tablet $resizePhoto1 = new ResizeImage($tabletPath, '', $tabletFolder, '735', '222'); // if the resize to 300px is unsuccessful if (!$resizePhoto1->resize()) { // echo 'Unable to resize image to 735 pixels'; // (development only) } // resize image to 320px by 160px for mobile $resizePhoto2 = new ResizeImage($mobilePath, '', $mobileFolder, '320', '160'); // if the resize to 400px is unsuccessful if (!$resizePhoto2->resize()) { // echo 'Unable to resize image to 320 pixels'; // (development only) } // if the new resized thumb, the tablet and the desktop image exist it worked so return['ok'] true! if (file_exists($mobilePath) && file_exists($tabletPath) && file_exists($desktopPath)) { $result['banner_img'] = basename($mobilePath); $result['resized'] = true; return $result; } else { return false; } }
<?php require 'ResizeImage.php'; $ResizeImage = new ResizeImage(); $ResizeImage->setImageToResize("Desert.jpg"); $ResizeImage->setNewWidth('300'); $ResizeImage->setNewHeight('300'); $ResizeImage->setRatio(true); $ResizeImage->setNewImageName('Desert_resized'); $ResizeImage->setSaveFolder(__DIR__ . DIRECTORY_SEPARATOR); $result = $ResizeImage->resize(); print_r($result);
function _makeThumbnail($height, $width, $personId) { $person = new Person(); $person->personId = $personId; $person->populate(); $picFile = ''; if ($person->activePhoto > 0) { $attachmentId = $person->activePhoto; $attachment = new Attachment(); $attachment->attachmentId = $attachmentId; $attachment->populate(); $db = Zend_Registry::get('dbAdapter'); $sql = "select data from attachmentBlobs where attachmentId = " . $attachmentId; $stmt = $db->query($sql); $row = $stmt->fetch(); $picFile = tempnam('/tmp', 'patpic'); file_put_contents($picFile, $row['data']); $stmt->closeCursor(); } else { $patientDir = Zend_Registry::get('config')->document->legacyStorePath . '/' . $personId; if ($personId == 0 || !file_exists($patientDir)) { $this->noPictureAction(); } $dir = dir($patientDir); $picturePath = array(); while (false !== ($entry = $dir->read())) { if (preg_match('/.*_pat_pic([0-9]+.*).jpg/', $entry, $matches)) { $timestamp = strtotime($matches[1]); if (!isset($picturePath['timestamp']) || isset($picturePath['timestamp']) && $timestamp > $picturePath['timestamp']) { $picturePath['timestamp'] = $timestamp; $picturePath['path'] = $patientDir . '/' . $entry; } } } $picFile = $picturePath['path']; } if (!file_exists($picFile)) { $this->noPictureAction(); } $patientPicture = new ResizeImage(); $patientPicture->load($picFile); $patientPicture->resize((int) $width, (int) $height); return $patientPicture; }