How do I resize an image with PHP using imagecopyresampled and then get the contents -
i'm resizing image , writing file. i've since had need store in amazon need contents of resized image. can done without first writing file?
this current code looks like:
$success = $src_img && @imagecopyresampled( $new_img, $src_img, $dst_x, $dst_y, 0, 0, $new_width, $new_height, $img_width, $img_height ) && imagejpeg($new_img, $new_file_path, $image_quality); // free memory (imagedestroy not delete files): @imagedestroy($src_img); @imagedestroy($new_img); $type = $this->get_file_type($new_file_path); $binary = file_get_contents($new_file_path); $image = $this->get_user_path() . $version . '/' . $file_name; $response = $this->s3->create_object(aws_s3_bucket, $image, array( 'body' => $binary, 'contenttype' => $type, 'acl' => amazons3::acl_public)); if ($response->isok()) { // success }
how can file contents without first writing file?
you need wrap imagejpeg($new_img, null, $image_quality)
output buffer commands:
ob_start(); imagejpeg($new_img, null, $image_quality); $binary = ob_get_clean();
Comments
Post a Comment