问题
I am now using the following method to store an image to server from input file type
$image = $request->file('file');
$filename = $item->itemId . '.png';
Storage::disk('s3')->put('/'.$filename, file_get_contents($image), 'public');
and I found method to rotate the image with PHP
$filename = 'test.jpg';
$degrees = 180;
header('Content-type: image/jpeg');
$source = imagecreatefromjpeg($filename);
$rotate = imagerotate($source, $degrees, 0);
imagejpeg($rotate);
but I dont know how implement the code with $request->file('file')
Thanks!
回答1:
I am not sure where you are getting your functions from, imagecreatefromjpeg() and imagerotate(), but if you just use PHP's own, available functions (provided by Imagick), you can do something much simpler...
$image = new Imagick();
$image_filehandle = fopen('some/file.jpg', 'a+');
$image->readImageFile($image_filehandle );
$image->rotateImage("FFFFFF", 90); # Rotate 90 degrees, keep background of "FFFFFF" (white)
$image_icon_filehandle = fopen('some/file-rotated.jpg', 'a+');
$image->writeImageFile($image_icon_filehandle);
The background color ("FFFFFF") is applied here if the image rotates and leaves a certain amount of background (does not happen for rotate degrees in increments of 90).
来源:https://stackoverflow.com/questions/38734035/php-rotate-image-from-request-file