protected function createImageSet($src_image)
 {
     Yii::import('application.extensions.ImageCropper');
     //Yii::log("Load source img: ".memory_get_usage(true),"info","MemmorySize");
     $cropper = new ImageCropper($src_image);
     $parts = preg_split('/[\\/\\\\]/', $src_image);
     $fileName = array_pop($parts);
     foreach ($this->pictures() as $type => $pic) {
         if (isset($pic['vertical']) || isset($pic['horizontal'])) {
             $Info = getimagesize($src_image);
             $orientation = $Info[0] < $Info[1] ? 'vertical' : 'horizontal';
             if (isset($pic[$orientation])) {
                 $w = $pic[$orientation]['w'];
                 $h = $pic[$orientation]['h'];
             }
         } else {
             $w = $pic['w'];
             $h = $pic['h'];
         }
         $filePath = $_SERVER['DOCUMENT_ROOT'] . $pic['path'] . $fileName;
         if ($w == null && $h == null) {
             if (!copy($src_image, $filePath)) {
                 return false;
             }
         } else {
             //Yii::log("Before resize \"".$type."\": ".memory_get_usage(true),"info","MemmorySize");
             if (!$cropper->resize_and_crop($filePath, $w, $h)) {
                 return false;
             }
             //Yii::log("After resize \"".$type."\"".memory_get_usage(true),"info","MemmorySize");
         }
     }
     $cropper = null;
     return $fileName;
 }
Esempio n. 2
0
 public function afterSave($event)
 {
     parent::afterSave($event);
     $newNames = array();
     $i = 0;
     foreach ($this->fields as $field) {
         if ($this->owner->{$field} instanceof CUploadedFile) {
             //generating the new filename and subtituting it in the entry
             $fileName = $newNames[$field] = preg_replace('/\\*([a-zA-Z_]+[a-zA-Z0-9_]*)\\*/e', '\\$this->owner->$1', $this->nameMask) . '.jpg';
             if ($this->prependFileName) {
                 $fileName = $field . '_' . $fileName;
             }
             $cropper = new ImageCropper();
             //creating the original image
             if ($this->resize) {
                 $cropper->resize_and_crop($this->owner->{$field}->tempName, self::getImagePath($fileName), $this->resizeTo[$i][0], $this->resizeTo[$i][1], $this->fileQuality, true);
             } else {
                 $this->owner->{$field}->saveAs(self::getImagePath($fileName));
             }
             //and now, the thumbnail
             if ($this->hasThumb) {
                 $thumbName = $this->generateThumbName($fileName);
                 $cropper->resize_and_crop(self::getImagePath($fileName), self::getImagePath($thumbName), $this->thumbSize[$i][0], $this->thumbSize[$i][1], $this->thumbQuality, true);
             }
         }
         ++$i;
     }
     //now we need to update the entry with the new filename
     if (sizeof($newNames) > 0) {
         $reg = $this->owner->findByPk($this->owner->primaryKey);
         foreach ($newNames as $field => $newName) {
             $reg->{$field} = $newName;
         }
         $reg->save(false);
     }
 }
<?php

namespace cd;

set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../core/');
require_once 'core.php';
require_once 'ImageCropper.php';
$file = '/home/ml/Skrivbord/DSC_1853.JPG';
$x = new ImageCropper($file);
$x->crop(500, 500, 1200, 1200);
$x->render('png', 'cropped.png');