示例#1
0
 /**
  * Cria uma miniatura da imagem nas dimensões solicitadas.
  *
  * @param string $file
  * @param int    $width
  * @param int    $height
  *
  * @return string
  */
 public static function CreateThumbnail($file, $width = 800, $height = 600)
 {
     $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
     $size = new \Imagine\Image\Box($width, $height);
     $destination = public_path() . "/img/{$width}-{$height}/";
     $fileName = self::GetFileName($file);
     if (file_exists($destination . $fileName)) {
         return url("/img/{$width}-{$height}/" . $fileName);
     }
     if (!file_exists($destination)) {
         @mkdir($destination, 0777);
     }
     $thumbnail = \Orchestra\Imagine\Facade::open($file)->thumbnail($size, $mode);
     $thumbnail->save($destination . $fileName);
     return url("/img/{$width}-{$height}/" . $fileName);
 }
示例#2
0
 /**
  * Obtiene las dimensiones de un archivo de imágen.
  *
  * La ruta de la imágen debe ser relativa al servidor.
  *
  * @param  string $image
  * @return Imagine\Image\Box
  */
 function imgsize($image)
 {
     $image = normalize_path(public_path($image));
     if (file_exists($image) === false) {
         return '';
     }
     $image = Imagine::open($image);
     return $image->getSize();
 }
示例#3
0
 private function createImage($width, $height, $suffix, $filename)
 {
     $name = explode('.', $filename)[0];
     $extension = explode('.', $filename)[1];
     $mode = ImageInterface::THUMBNAIL_INSET;
     $size = new Box($width, $height);
     $newImage = Imagine::open(storage_path('app/' . $filename))->thumbnail($size, $mode);
     $destination = "{$name}.{$suffix}.{$extension}";
     $newImage->save(storage_path('app/' . $destination));
 }