Yii2 - 想象一下在没有临时文件的情况下创建新图像

Yii2 - Imagine create new image without temp file

我不熟悉 imagine library(在 yii2 中),我想知道有没有一种方法可以在不存储原始文件的情况下编辑新上传的图像。

目前我在做这样的事情:

// 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...

所以总结一下:有没有办法跳过保存原始临时图像的步骤?

您应该只使用 PHP 创建的临时文件:

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

阅读更多:http://www.yiiframework.com/doc-2.0/yii-web-uploadedfile.html#$tempName-detail