Skip to content

Commit

Permalink
Laravel 5.1 Job Support, Image Size from ImageFile Object
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunmangukiya committed Apr 4, 2016
1 parent 3996838 commit 282cfb8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/Commands/ResizeImages.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php namespace TarunMangukiya\ImageResizer\Commands;

use App\Commands\Command;

use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;
use Illuminate\Contracts\Queue\ShouldQueue;

use Intervention\Image\ImageManager as InterImage;
use TarunMangukiya\ImageResizer\ImageFile;

class ResizeImages extends Command implements SelfHandling, ShouldBeQueued {
class ResizeImages extends Job implements SelfHandling, ShouldQueue
{

use InteractsWithQueue, SerializesModels;

Expand Down Expand Up @@ -50,12 +50,12 @@ public function __construct(ImageFile $imageFile, $type_config)
*/
public function handle()
{
\Log::info('ImageResizer for queue: '.$this->imageFile->fullpath);
\Log::info('ImageResizer for queue: '.$this->imageFile->fullpath);

// Initialize InterImage Instance first
// Initialize InterImage Instance first
$this->interImage = new InterImage;

$sizes = $this->type_config['sizes'];
$sizes = $this->type_config['sizes'];
$compiled_path = $this->type_config['compiled'];
$filename = $this->imageFile->filename;

Expand Down Expand Up @@ -89,7 +89,7 @@ public function handle()
$this->resizeImage($this->imageFile->fullpath, $target, $size);
}
}
}
}


public function resizeImage($fullpath, $target, $size)
Expand Down
31 changes: 30 additions & 1 deletion src/ImageFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class ImageFile
* @var string
*/
public $extension;

/**
* File extension of current file
*
* @var string
*/
public $size = [];

/**
* File name of current file
Expand Down Expand Up @@ -68,6 +75,7 @@ public function setFileInfoFromPath($path)
$this->extension = array_key_exists('extension', $info) ? $info['extension'] : null;

if (file_exists($path) && is_file($path)) {
$this->size = getimagesize($path);
$this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
}

Expand All @@ -90,14 +98,35 @@ public function filesize()
return false;
}

/**
* Get image file size
*
* @return mixed
*/
public function sizes()
{
if(empty($this->size)){
$path = $this->fullpath;

if (file_exists($path) && is_file($path)) {
$this->size = getimagesize($path);
return $this->size;
}
}
else {
return $this->size;
}
return false;
}

/**
* Get file path by string
*
* @return string
*/
public function __toString ()
{
return $this->getFileName();
return $this->getBaseName();
}

}
7 changes: 3 additions & 4 deletions src/ImageResizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ public function upload($type, $input, $name, $crop = null, $rotate = null)
else {
throw new \TarunMangukiya\ImageResizer\Exception\InvalidInputException("Invalid Input for Image Resizer.");
}

// crop the image if enabled
if($crop_enabled) {
$file = $this->transformImage($original_file, $type_config, $crop, $rotate);
Expand Down Expand Up @@ -422,15 +421,15 @@ public function get($type, $size, $basename)

// File Name match
$pathinfo = pathinfo($basename);
$filename = $pathinfo['filename'];
$file_extension = $pathinfo['extension'];
$filename = isset($pathinfo['filename'])?$pathinfo['filename']:'';
$file_extension = isset($pathinfo['extension'])?$pathinfo['extension']:'';

// Match Proper Extension
$extension = $s[3];
if($extension == 'original') $extension = $file_extension;
$new_path = "{$compiled_path}/{$size}/{$filename}-{$width}x{$height}.{$extension}";
}
var_dump($new_path);

if(file_exists($new_path)){
return \URL::to($new_path);
}
Expand Down

0 comments on commit 282cfb8

Please sign in to comment.