0

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);
Pez
  • 1
  • 2

1 Answers1

0

I have managed to get this to work but now the second resize is quick but sending it to S3 is very slow, it takes about 30 second to upload a very small image.

Has anyone had any problem with putting multiple objects to S3 in one go?

Pez
  • 1
  • 2
  • Did you ever figure this out? I'm about to embark on the same path you've been down, would be great if you can share some knowledge! – dearsina Jul 04 '16 at 20:52