我正在尝试创建旋转图像功能,我尝试旋转的图像位于我的S3存储桶中。
所以我正在尝试创建一个从我的桶中抓取图像的功能,保存本地副本,旋转图像,将图像上传回S3。
我的剧本:
$s3 = new S3(myAccessKey, mySecretKey);
$target_path = CLOUDFRONTURLFORPHOTOS; //Cloudfront URL for photos
$filetodownload = $target_path."filename.jpg";
$savetofile = "foldername/filename.jpg";
$s3->getObject(MYBUCKET,CLOUDFRONTURLFORPHOTOS, array("filename.jpg" => $savetofile));
rotateImage($destpath, $destpath, $degree);
if ($s3->putObjectFile($destpath, MYBUCKET, $imagepath, S3::ACL_PUBLIC_READ)) {
echo 'Photo has been rotated and uploaded to the Photo Bucket.';
}
function rotateImage($sourceFile,$destImageName,$degreeOfRotation)
{
//get the detail of the image
$imageinfo=getimagesize($sourceFile);
switch($imageinfo['mime'])
{
//create the image according to the content type
case "image/jpg":
case "image/jpeg":
case "image/pjpeg": //for IE
$src_img=imagecreatefromjpeg("$sourceFile");
break;
case "image/gif":
$src_img = imagecreatefromgif("$sourceFile");
break;
case "image/png":
case "image/x-png": //for IE
$src_img = imagecreatefrompng("$sourceFile");
break;
}
//rotate the image according to the spcified degree
$src_img = imagerotate($src_img, $degreeOfRotation, 0);
//output the image to a file
imagejpeg ($src_img,$destImageName);
}
我收到此错误:
Warning: S3::getObject(bucketname, public-read): [0] Unable to open save file for writing: Array in S3.php on line 326 Warning: imagerotate() expects parameter 1 to be resource, null given in myfile.php on line 300 Warning: imagejpeg() expects parameter 1 to be resource, boolean given in myfile.php on line 303
请指教。我的代码中缺少什么?或者是否有更好的方法直接在S3存储桶中旋转图像而无需在本地下载文件?