File indexing completed on 2024-12-22 05:36:23
0001 <?php 0002 /** 0003 * ocs-webserver 0004 * 0005 * Copyright 2016 by pling GmbH. 0006 * 0007 * This file is part of ocs-webserver. 0008 * 0009 * This program is free software: you can redistribute it and/or modify 0010 * it under the terms of the GNU Affero General Public License as 0011 * published by the Free Software Foundation, either version 3 of the 0012 * License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU Affero General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Affero General Public License 0020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 **/ 0022 0023 class Local_Filter_PrepareImage implements Zend_Filter_Interface 0024 { 0025 0026 public function filter($value) 0027 { 0028 #Zend_Debug::dump($value); 0029 0030 0031 #die(); 0032 $image = new Imagick(); 0033 $image->readImage($value); 0034 0035 $pathVals = explode("/", $value); 0036 0037 $savePath = substr($value, 0, strrpos($value, "/") + 1); 0038 $origFileName = substr($pathVals[count($pathVals) - 1], 0, strrpos($pathVals[count($pathVals) - 1], ".")); 0039 $goodFileName = $this->cleanFileName(substr($pathVals[count($pathVals) - 1], 0, strrpos($pathVals[count($pathVals) - 1], "."))); 0040 0041 $normalFileName = $savePath . $goodFileName . ".jpg"; 0042 0043 $bgImg = new Imagick(); 0044 $bgImgPrint = new Imagick(); 0045 0046 $origDims = $image->getImageGeometry(); 0047 0048 $targetWidth = 735; 0049 $targetHeight = 520; 0050 0051 if ($origDims['width'] > $targetWidth) { 0052 $newWidth = $targetWidth; 0053 $newHeight = (($newWidth * $origDims['height']) / $origDims['width']); 0054 0055 0056 if ($newHeight > $targetHeight) { 0057 $newHeight = $targetHeight; 0058 $newWidth = (($newHeight * $origDims['width']) / $origDims['height']); 0059 $image->resizeImage($newWidth, $newHeight, null, null); 0060 #$image->cropImage($newWidth,$newHeight,0,0); 0061 } else { 0062 $image->resizeImage($newWidth, $newHeight, null, null); 0063 } 0064 0065 0066 } elseif ($origDims['height'] > $targetHeight) { 0067 $newHeight = $targetHeight; 0068 $newWidth = (($newHeight * $origDims['width']) / $origDims['height']); 0069 0070 $image->resizeImage($newWidth, $newHeight, null, null); 0071 } 0072 0073 $image->writeImage($normalFileName); 0074 0075 #$emptyImg = new Imagick(); 0076 #$emptyImg->newImage(129,77,"none"); 0077 #$emptyImg->setImageFormat('png'); 0078 0079 $thumbImg = $image; 0080 0081 0082 $thumbWidth = 292; 0083 $thumbHeight = (($thumbWidth * $origDims['height']) / $origDims['width']); 0084 if ($thumbHeight < 219) { 0085 $thumbHeight = 219; 0086 $thumbWidth = (($thumbHeight * $origDims['width']) / $origDims['height']); 0087 $thumbImg->resizeImage($thumbWidth, $thumbHeight, null, null); 0088 $thumbImg->cropImage(292, 219, 0, 0); 0089 } else { 0090 $thumbImg->resizeImage($thumbWidth, $thumbHeight, null, null); 0091 $thumbImg->cropImage($thumbWidth, 219, 0, 0); 0092 } 0093 0094 //$thumbImg->setImageFormat('jpg'); 0095 0096 #$picOverlay = new Imagick(); 0097 #$picOverlay->readImage($_SERVER['DOCUMENT_ROOT']."/images/pic_over.png"); 0098 0099 #$emptyImg->compositeImage($thumbImg,imagick::COMPOSITE_DEFAULT,9,9); 0100 #$emptyImg->compositeImage($picOverlay,imagick::COMPOSITE_DEFAULT,0,0); 0101 /* 0102 0103 0104 $image->roundCorners(10,10); 0105 0106 $bgImg->newImage($sideLength,$sideLength, new ImagickPixel('#e8e8e8')); 0107 $bgImgPrint->newImage($sideLength,$sideLength, new ImagickPixel('#ffffff')); 0108 0109 $bgImg->setImageFormat('jpg'); 0110 $bgImgPrint->setImageFormat('jpg'); 0111 0112 $bgImg->compositeImage($image,imagick::COMPOSITE_DEFAULT,0,0); 0113 $bgImgPrint->compositeImage($image,imagick::COMPOSITE_DEFAULT,0,0); 0114 */ 0115 0116 0117 # $fileName = substr($pathVals[count($pathVals)-1],0,strrpos($pathVals[count($pathVals)-1],".")).".jpg"; 0118 $fileNameThumb = "thumb_" . $goodFileName . ".jpg"; 0119 0120 $thumbImg->writeImage(substr($value, 0, strrpos($value, "/")) . "/" . $fileNameThumb); 0121 0122 0123 $thumbImg->destroy(); 0124 #$picOverlay->destroy(); 0125 #$emptyImg->destroy(); 0126 0127 if ($origFileName != $goodFileName) { 0128 unlink($value); 0129 } 0130 0131 0132 return $normalFileName; 0133 } 0134 0135 private function cleanFileName($fileName) 0136 { 0137 $newFileName = strtr($fileName, " ", "_"); 0138 0139 return $newFileName; 0140 } 0141 0142 private function getWidth($width, $height) 0143 { 0144 return ($width * 209) / $height; 0145 } 0146 0147 private function getHeight($width, $height) 0148 { 0149 return ($height * 209) / $width; 0150 } 0151 0152 }