Exemple #1
0
 /**
  * @expectedException WideImage_InvalidImageSourceException
  */
 function testInvalidImageFile()
 {
     WideImage::loadFromFile(IMG_PATH . 'fakeimage.png');
 }
Exemple #2
0
 function png_jpeg_to_jpg($link)
 {
     //		var_dump($link);
     //		var_dump(pathinfo($link, PATHINFO_EXTENSION));exit;
     if (pathinfo($link, PATHINFO_EXTENSION) == 'jpeg') {
         $oldName = $link;
         $new_name = substr($link, 0, -5);
         WideImage::loadFromFile($link)->saveToFile($new_name . ".jpg", 80);
         unlink($oldName);
     } elseif (pathinfo($link, PATHINFO_EXTENSION) == 'png') {
         $oldName = $link;
         $new_name = substr($link, 0, -4);
         WideImage::loadFromFile($link)->saveToFile($new_name . ".jpg", 80);
         unlink($oldName);
     }
 }
Exemple #3
0
 /**
  *
  * @param type $dto
  * @param type $endereco
  */
 public static function showImage($dto, $endereco)
 {
     $endereco = explode("/", $endereco);
     $nameImage = array_reverse($endereco);
     $pasta = current(explode('application', __DIR__)) . 'data' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'anexo-artefato' . DIRECTORY_SEPARATOR;
     $fileinfo = pathinfo($pasta . $nameImage[0]);
     $image = \WideImage::loadFromFile($pasta . $nameImage[0]);
     if ($dto->getResize()) {
         $image = $image->resize($dto->getWidth(), $dto->getHeight(), 'outside');
     }
     if ($dto->getCrop()) {
         $image = $image->resize($dto->getWidth(), $dto->getHeight(), 'outside')->crop('50% - ' . ceil($dto->getWidth() / 2), '50% - ' . ceil($dto->getHeight() / 2), $dto->getWidth(), $dto->getHeight());
     }
     unset($dto);
     unset($pasta);
     $image->output(strtolower($fileinfo['extension']));
     $image->destroy();
 }
Exemple #4
0
 /**
  * Generates a thumbnail image for a slice
  *
  * @param $thumb_x
  * @param $thumb_y
  * @param bool $keep_aspect
  * @param null $background_color
  * @param string $extension
  *
  */
 public function generateThumbnail($thumb_x, $thumb_y, $keep_aspect = true, $background_color = null, $extension = "thumb")
 {
     $slices_dir = dirname($this->File->getFullPath());
     $thumb_path = $this->getThumbFullPath($extension);
     // get the slice image
     RokGallery_Memory::adjustLimitForImage($this->xsize, $this->ysize);
     $slice_image = WideImage::loadFromFile($this->getFullPath());
     if ($background_color == 'transparent' || empty($background_color)) {
         $background_color = null;
     }
     // if he image size is smaller then the thumbnail size
     // resize the canvas with optioned color and place in center
     if ($this->xsize < $thumb_x && $this->ysize < $thumb_y) {
         // Resize canvas
         RokGallery_Memory::adjustLimitForImage($thumb_x, $thumb_y);
         $thumb_image = $slice_image->resizeCanvas($thumb_x, $thumb_y, 'center', 'center', $background_color == null ? $background_color : $slice_image->allocateColor(RokGallery_Helper::html2rgb($background_color)));
         $slice_image->destroy();
         unset($slice_image);
         // write out image
         $thumb_image->saveToFile($thumb_path, RokGallery_Helper::getImageQuality($this->File->type));
         RokGallery_Queue_FileCreate::add($thumb_path);
         $thumb_image->destroy();
         unset($thumb_image);
     } else {
         if ($keep_aspect) {
             // Keep the aspect Ratio
             RokGallery_Memory::adjustLimitForImage($thumb_x, $thumb_y);
             $thumb_image_after_resize = $slice_image->resize($thumb_x, $thumb_y);
             $slice_image->destroy();
             unset($slice_image);
             // fill in blank space
             RokGallery_Memory::adjustLimitForImage($thumb_x, $thumb_y);
             $thumb_image = $thumb_image_after_resize->resizeCanvas($thumb_x, $thumb_y, 'center', 'center', $background_color == null ? $background_color : $thumb_image_after_resize->allocateColor(RokGallery_Helper::html2rgb($background_color)));
             $thumb_image_after_resize->destroy();
             unset($thumb_image_after_resize);
             // write out image
             $thumb_image->saveToFile($thumb_path, RokGallery_Helper::getImageQuality($this->File->type));
             RokGallery_Queue_FileCreate::add($thumb_path);
             $thumb_image->destroy();
             unset($thumb_image);
         } else {
             // Create thumbnail but dont make thumbnail keep the aspect ratio
             $source_aspect_ratio = $this->xsize / $this->ysize;
             $desired_aspect_ratio = $thumb_x / $thumb_y;
             $temp_width = $thumb_x;
             $temp_height = $thumb_y;
             $temp_left = 0;
             $temp_top = 0;
             if ($source_aspect_ratio > $desired_aspect_ratio) {
                 $temp_height = $thumb_y;
                 $temp_width = (int) round($thumb_y * $source_aspect_ratio);
                 $temp_left = (int) round(($temp_width - $thumb_x) / 2);
                 $temp_top = 0;
             } elseif ($source_aspect_ratio < $desired_aspect_ratio) {
                 $temp_width = $thumb_x;
                 $temp_height = (int) round($thumb_x / $source_aspect_ratio);
                 $temp_left = 0;
                 $temp_top = (int) round(($temp_height - $thumb_y) / 2);
             }
             RokGallery_Memory::adjustLimitForImage($temp_width, $temp_height);
             $thumb_image_after_resize = $slice_image->resize($temp_width, $temp_height);
             $slice_image->destroy();
             unset($slice_image);
             RokGallery_Memory::adjustLimitForImage($thumb_x, $thumb_y);
             $thumb_image = $thumb_image_after_resize->crop($temp_left, $temp_top, $thumb_x, $thumb_y);
             $thumb_image_after_resize->destroy();
             unset($thumb_image_after_resize);
             // write out image
             $thumb_image->saveToFile($thumb_path, RokGallery_Helper::getImageQuality($this->File->type));
             RokGallery_Queue_FileCreate::add($thumb_path);
             $thumb_image->destroy();
             unset($thumb_image);
         }
     }
 }