I can not get the code below to work. I am saving the original image to my S3 bucket, and then resizing 2 variations of the same image and sending the string generated by PHPThumb_GdThumb to S3 but the resized images have 0kb and contain error.
The image is written fine to mybucket/object and mybucket/object/thumb but the image in thumb folder is 0kb and contains error.
Here is my code:
// 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);