我无法让下面的代码工作。我将原始图像保存到我的 S3 存储桶中,然后调整同一图像的 2 个变体的大小并将 PHPThumb_GdThumb 生成的字符串发送到 S3,但调整大小的图像有 0kb 并包含错误。
图像可以很好地写入mybucket/object和mybucket/object/thumb,但 thumb 文件夹中的图像是 0kb 并且包含错误。
这是我的代码:
// Add Original to S3 before doing any cropping
$s3_path = 'mybucket/object';
$S3_folder->addToBucket($s3_path.'/'.$filename, $path);
$GDImage = new PHPThumb_GdThumb("{$path}");
if (!$GDImage->getHasError())
{
// get images dimensions
$dimensions = $GDImage->getCurrentDimensions();
$imageWidth = (int) $dimensions['width'];
$imageHeight = (int) $dimensions['height'];
// thumbnails
if ($imageHeight > $imageWidth)
{
$thumbPercent = floor(self::THUMB_SIZE / $imageHeight * 100);
} else if ($imageHeight < $imageWidth)
{
$thumbPercent = floor(self::THUMB_SIZE / $imageWidth * 100);
} else
{
// it's a square use either
$thumbPercent = floor(self::THUMB_SIZE / $imageWidth * 100);
}
if ($imageHeight > self::THUMB_SIZE)
{
$img_string = $GDImage->resizePercent($thumbPercent)
->cropFromCenter(self::THUMB_SIZE)
->getImageAsString();
} else
{
$img_string = $GDImage->getImageAsString();
}
$S3_folder->addToBucket($s3_path.'/thumb/'.$filename, $img_string);