Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3962920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:09:13+00:00 2026-05-20T03:09:13+00:00

I am using S3 to store images and I am resizing and compressing images

  • 0

I am using S3 to store images and I am resizing and compressing images before it gets uploaded using PHP. I’m using this class for storing the images to an S3 bucket – http://undesigned.org.za/2007/10/22/amazon-s3-php-class

This all works fine if I’m not doing any file processing before the file is uploaded because it reads the file upload from the $_FILES array.

The problem is I am resizing and compressing the image before storing to the S3 bucket. So I’m no longer able to read from the $_FILES array.

The functions for resizing:

            public function resizeImage($newWidth, $newHeight, $option="auto")
        {
            // *** Get optimal width and height - based on $option
            $optionArray = $this->getDimensions($newWidth, $newHeight, $option);

            $optimalWidth  = $optionArray['optimalWidth'];
            $optimalHeight = $optionArray['optimalHeight'];


            // *** Resample - create image canvas of x, y size
            $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
            imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);


            // *** if option is 'crop', then crop too
            if ($option == 'crop') {
                $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
            }
        }

The script I am using to store the file after resizing and compressing to a local directory:

            public function saveImage($savePath, $imageQuality="100")
        {
            // *** Get extension
            $extension = strrchr($savePath, '.');
            $extension = strtolower($extension);

            switch($extension)
            {
                case '.jpg':
                case '.jpeg':
                    if (imagetypes() & IMG_JPG) {
                        imagejpeg($this->imageResized, $savePath, $imageQuality);
                    }
                    break;

                case '.gif':
                    if (imagetypes() & IMG_GIF) {
                        imagegif($this->imageResized, $savePath);
                    }
                    break;

                case '.png':
                    // *** Scale quality from 0-100 to 0-9
                    $scaleQuality = round(($imageQuality/100) * 9);

                    // *** Invert quality setting as 0 is best, not 9
                    $invertScaleQuality = 9 - $scaleQuality;

                    if (imagetypes() & IMG_PNG) {
                         imagepng($this->imageResized, $savePath, $invertScaleQuality);
                    }
                    break;

                // ... etc

                default:
                    // *** No extension - No save.
                    break;
            }

            imagedestroy($this->imageResized);
        }

with this PHP code to invoke it:

                $resizeObj = new resize("$images_dir/$filename");                   
                $resizeObj -> resizeImage($thumbnail_width, $thumbnail_height, 'crop');                 
                $resizeObj -> saveImage($images_dir."/tb_".$filename, 90);

How do I modify the code above so I can pass it through this function:

$s3->putObjectFile($thefile, "s3bucket", $s3directory, S3::ACL_PUBLIC_READ)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:09:13+00:00Added an answer on May 20, 2026 at 3:09 am

    Used the copy PHP function to save to a temporary directory and then used the S3 function to read from the directory. Once the S3 upload is complete, the file is deleted from the temporary directory using the unlink function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to store images in my mySQL database using the CodeIgniter PHP
I want to store images into sql using c# application. So I have this
I'm making a Space Invaders game in C#, using Bitmap to store images for
copy('https://graph.facebook.com/$fbid/picture?type=large', 'images/$fbid.jpg'); i am using the above code to store the image locally ..
I successfully stored image files in MongoDB using PHP, when i retrieve images from
i'm using Ruby on Rails and i want to store images into the cassandra
currently i am using acts_as_attachment and also using Capistrano. I want to store images
I want to store images in an array on every click before sending the
I want to store images and sounds using JS. Is there any API for
i am using a class written by someone to resize the image and store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.