CMS MADE SIMPLE FORGE

Cataloger

 

[#7523] add crop

avatar
Created By: Maxim (max_rip)
Date Submitted: 2012-01-26 12:41

Assigned To:
Resolution: None
State: Open
Summary:
add crop
Detailed Description:
Add crop images for function imageTransform.
Settings for crop, image size = 150x100
150 - width
100 - height

Start diff

Index: Cataloger.Image.php
===================================================================
--- Cataloger.Image.php	(revision 122)
+++ Cataloger.Image.php	(working copy)
@@ -104,24 +104,44 @@
         $it = new Image_Transform;
         $img = $it->factory($config['image_manipulation_prog']);
         $img->load($srcSpec);
-        if ($img->img_x < $img->img_y)
-            {
-            $long_axis = $img->img_y;
-            }
-        else
-            {
-            $long_axis = $img->img_x;
-            }
+        if(strpos($size,'x') === FALSE){
+            if ($img->img_x < $img->img_y)
+                {
+                $long_axis = $img->img_y;
+                }
+            else
+                {
+                $long_axis = $img->img_x;
+                }
 
-        if ($long_axis > $size)
-            {
-            $img->scaleByLength($size);
-            $img->save($destSpec, 'jpeg');
+            if ($long_axis > $size)
+                {
+                $img->scaleByLength($size);
+                $img->save($destSpec, 'jpeg');
+                }
+            else
+                {
+                $img->save($destSpec, 'jpeg');
+                }
+        } else {
+            $size= explode("x",$size);
+            $ratio_orig =$img->img_x/$img->img_y;
+            if ($size[0]/$size[1] > $ratio_orig) {
+                 $new_height = $size[0]/$ratio_orig;
+                 $new_width = $size[0];
+            } else {
+                 $new_width = $size[1]*$ratio_orig;
+                 $new_height = $size[1];
             }
-        else
-            {
+            $x_mid = $new_width/2;  //horizontal middle
+            $y_mid = $new_height/2; //vertical middle
+            $img->resize($new_width,$new_height);
+            $x=(int)($x_mid-($size[0]/2));
+            $y=(int)($y_mid-($size[1]/2));
+            $img->crop($x,$y,$size[0],$size[1]);
             $img->save($destSpec, 'jpeg');
-            }
+
+        }
         $img->free();
     }
 ?>

History