Fixed crop calculation
authorMarcel Werk <burntime@woltlab.com>
Mon, 16 Apr 2012 18:36:12 +0000 (20:36 +0200)
committerMarcel Werk <burntime@woltlab.com>
Mon, 16 Apr 2012 18:36:12 +0000 (20:36 +0200)
wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php
wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php

index 306838f0f35ddf48b2e35ecf85dc851720225b5a..71bfb26b69851fb991e1dcdf2d88394c94b30cd1 100644 (file)
@@ -113,18 +113,20 @@ class GDImageAdapter implements IImageAdapter {
                                $height = $maxHeight;
                                $width = round($this->width * ($height / $this->height));
                        }
-                       
                }
                else {
-                       $width = $height = $maxWidth;
+                       $width = $maxWidth;
+                       $height = $maxHeight;
                        
-                       if ($sourceWidth > $sourceHeight) {
-                               $x = ceil(($sourceWidth - $sourceHeight) / 2);
-                               $sourceWidth = $sourceHeight;
+                       if ($maxWidth / $this->width < $maxHeight / $this->height) {
+                               $cut = (($sourceWidth * ($maxHeight / $this->height)) - $maxWidth) / ($maxHeight / $this->height);
+                               $x = ceil($cut / 2);
+                               $sourceWidth = $sourceWidth - $x * 2;
                        }
                        else {
-                               $y = ceil(($sourceHeight - $sourceWidth) / 2);
-                               $sourceHeight = $sourceWidth;
+                               $cut = (($sourceHeight * ($maxWidth / $this->width)) - $maxHeight) / ($maxWidth / $this->width);
+                               $y = ceil($cut / 2);
+                               $sourceHeight = $sourceHeight - $y * 2;
                        }
                }
                
index 5bfecba4bfe707f4d0f042ff823f275c0d1eb6d6..71c6450d0dbc67eaef5d6e608c8df64817d72f05 100644 (file)
@@ -82,6 +82,7 @@ class ImagickImageAdapter implements IImageAdapter {
         * @see wcf\system\image\adapter\IImageAdapter::createThumbnail()
         */
        public function createThumbnail($maxWidth, $maxHeight, $obtainDimensions = true) {
+               /* todo: obtainDimensions=false doesn't work */
                $thumbnail = $this->imagick;
                $thumbnail->cropThumbnailImage($maxWidth, $maxHeight);