Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Imagick: Write Image directly to Amazon S3?

Is it possible for me to use the writeImage function in Imagick to write an image directly to an S3 bucket? If so, how? I'm pretty new to the Amazon S3 SDK, so some help would be appreciated.

like image 860
user1204384 Avatar asked Mar 04 '26 18:03

user1204384


1 Answers

With writeImage, probably not (it takes a file path as argument, thus writing the file to the filesystem), but you can getImageBlob to get the image as binary string which you can then easily write to S3 with certain name. It would be easiest for you to use an S3 PHP library, there is one official in the AWS PHP SDK, or there are 3rd party libraries as well, such as this one:

https://github.com/mackstann/amazon-s3-php-class
// Put an object from a string:
$s3->putObject($string, $bucketName, $uploadName, S3::ACL_PUBLIC_READ)
like image 122
ddinchev Avatar answered Mar 06 '26 09:03

ddinchev