X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FImages.php;h=d024fcfb1ced3c08d28c94f0ea18c970c7294189;hp=1c0d86a904df7befc1b8d598464dca988e386829;hb=bdc42ad7d7a221122018aabd7e6064adb093498d;hpb=bde9b91a43255cc5a19063ba5efb1b5375ced5a4 diff --git a/DataObjects/Images.php b/DataObjects/Images.php index 1c0d86a9..d024fcfb 100644 --- a/DataObjects/Images.php +++ b/DataObjects/Images.php @@ -830,36 +830,13 @@ class Pman_Core_DataObjects_Images extends DB_DataObject $data = file_get_contents($file); - if($rotate){ - $data = $this->rotate(); - } - if(!empty($scaleWidth) || !empty($scaleHeight)){ - - $width = $this->width; - $height = $this->height; - - if(!empty($scaleWidth)){ - $width = $scaleWidth; - - if(empty($scaleHeight)){ - $height = $this->height * $scaleWidth / $this->width; - } - } - - if(!empty($scaleHeight)){ - $height = $scaleHeight; - - if(empty($scaleWidth)){ - $width = $this->width * $scaleHeight / $this->height; - } - } - - - + $data = $this->scale(false, $scaleWidth, $scaleHeight); } - + if($rotate){ + $data = $this->rotate($data); + } $base64 = 'data:' . $this->mimetype . ';base64,' . base64_encode($data); @@ -896,12 +873,17 @@ class Pman_Core_DataObjects_Images extends DB_DataObject return $page; } - function rotate() + function rotate($imageBlob = false) { - $imagick = new Imagick($this->getStoreName()); + if(empty($imageBlob)){ + $imagick = new Imagick($this->getStoreName()); + } else { + $imagick = new Imagick(); + $imagick->readImageBlob($imageBlob); + } $orientation = $imagick->getImageOrientation(); - + switch($orientation) { case Imagick::ORIENTATION_BOTTOMRIGHT: $imagick->rotateimage(new ImagickPixel('#00000000'), 180); // rotate 180 degrees @@ -919,4 +901,19 @@ class Pman_Core_DataObjects_Images extends DB_DataObject return $imagick->getImageBlob(); } + function scale($imageBlob = false, $width = 0, $height = 0) + { + if(empty($imageBlob)){ + $imagick = new Imagick($this->getStoreName()); + } else { + $imagick = new Imagick(); + $imagick->readImageBlob($imageBlob); + } + + $imagick->resizeimage($width, $height, Imagick::FILTER_LANCZOS, true, true); + + return $imagick->getImageBlob(); + + } + }