Esempio n. 1
0
 public function cropPercent($source_dir, $dest_dir, $percentage, $origin = 5)
 {
     if ($percentage > 99) {
         return false;
     }
     $size = getimagesize($source_dir);
     if (empty($size)) {
         return false;
     }
     $width =& $size[0];
     $height =& $size[1];
     $new_width = round($width * ((int) $percentage / 100));
     $new_height = round($height * ((int) $percentage / 100));
     return PHPWS_File::cropImage($source_dir, $dest_dir, $new_width, $new_height, $origin);
 }
Esempio n. 2
0
 public function resize($dst, $max_width, $max_height, $crop_to_fit = false)
 {
     if (!$this->width || !$this->height) {
         return false;
     }
     $src_proportion = $this->width / $this->height;
     $new_width = $this->width;
     $new_height = $this->height;
     if ($crop_to_fit) {
         if ($max_width > $this->width) {
             $crop_width = $new_width;
             $crop_height = $max_height;
         } elseif ($max_height > $this->height) {
             $crop_width = $max_width;
             $crop_height = $new_height;
         } elseif ($max_width <= $max_height) {
             $new_height = $max_height;
             $new_width = round($new_height * $src_proportion);
             $crop_width = $max_width;
             $crop_height = $new_height;
             if ($crop_to_fit && $crop_width > $new_width) {
                 $new_width = $max_width;
                 $new_height = round($new_width / $src_proportion);
             }
         } else {
             $new_width = $max_width;
             $new_height = round($new_width * $src_proportion);
             $crop_width = $new_width;
             $crop_height = $max_height;
         }
         PHPWS_File::scaleImage($this->getPath(), $dst, $new_width, $new_height);
         // testing purposes
         /*
          printf('<hr>w=%s h=%s<br>mw=%s mh=%s<br>nw=%s nh=%s<br>cw=%s ch=%s<hr>',
          $this->width, $this->height, $max_width, $max_height,
          $new_width, $new_height, $crop_width, $crop_height);
         */
         return PHPWS_File::cropImage($dst, $dst, $crop_width, $crop_height);
     } else {
         return PHPWS_File::scaleImage($this->getPath(), $dst, $max_width, $max_height);
     }
 }
Esempio n. 3
0
 public function resize($orig, $dst, $max_width, $max_height)
 {
     if (!$this->width || !$this->height) {
         return false;
     }
     $src_proportion = $this->width / $this->height;
     $new_width = $this->width;
     $new_height = $this->height;
     if ($max_width > $this->width) {
         $crop_width = $new_width;
         $crop_height = $max_height;
     } elseif ($max_height > $this->height) {
         $crop_width = $max_width;
         $crop_height = $new_height;
     } elseif ($max_width <= $max_height) {
         $new_height = $max_height;
         $new_width = round($new_height * $src_proportion);
         $crop_width = $max_width;
         $crop_height = $new_height;
         if ($crop_width > $new_width) {
             $new_width = $max_width;
             $new_height = round($new_width / $src_proportion);
         }
     } else {
         $new_width = $max_width;
         $new_height = round($new_width * $src_proportion);
         $crop_width = $new_width;
         $crop_height = $max_height;
     }
     \PHPWS_File::scaleImage($orig, $dst, $new_width, $new_height);
     return \PHPWS_File::cropImage($dst, $dst, $crop_width, $crop_height);
 }