Search code examples
phpyii2php-imagine

Yii2 - Imagine create new image without temp file


I'm new to imagine library (and in yii2 at all) and I wonder is there a way to edit a new uploaded image without storing the original file before.

Currently I do something like this:

// store original image (it will not be used anymore, so we will delete that later)
$myImage->saveAs($imageTempPath);

// save new imagine thumb
Image::thumbnail($imageTempPath, 120, 120)
    ->save(Yii::getAlias('uploads/test-photo.jpg'), ['quality' => 80]);

// delete original image...

So to summarize: Is there a way to skip the step with the saving of the original temp image?


Solution

  • You should simply use the temp file created by PHP :

    Image::thumbnail($myImage->tempName, 120, 120)
        ->save(Yii::getAlias('uploads/test-photo.jpg'), ['quality' => 80]);
    

    Read more : http://www.yiiframework.com/doc-2.0/yii-web-uploadedfile.html#$tempName-detail