Iphone imagecopy旋转我的图像
I'm building an HTML application that works with the ipad camera, and uploads the taken image to my server. When uploaded the image gets a watermark over it by using imagecopy().
Everything works fine when I test it on my computer, but for some reason, if I take a picture on ipad/ipod/iphone in portrait, the image WITH the watermark gets rotated to a landscape mode.
To clarify: the original picture is uploaded correctly, the image with the watermark is rotated. This does NOT happen when I try that on my computer with a portrait image.
Here is some code, if that helps (I use the Codeigniter framework). If you need any more code, just ask, although I don't think there's going anything wrong with the upload itself.
//The code for the imagecopy do add the watermark
$overlay = imagecreatefrompng(base_url() . 'assets/images/imgoverlay.png');
$img = imagecreatefromjpeg(base_url() . 'uploads/' . $config['file_name']);
$imageSize = getimagesize(base_url() . 'uploads/' . $config['file_name']);
$sx = imagesx($overlay);
$sy = imagesy($overlay);
$newWatermarkWidth = $imageSize[0];
$newWatermarkHeight = $sy * $newWatermarkWidth / $sx;
$test = imagecopy(
$img,
$overlay,
$imageSize[0]/2 - $newWatermarkWidth/2,
$imageSize[1] - $newWatermarkHeight,
0,
0,
imagesx($img),imagesy($img)
);
Many thanks!
我正在构建一个与ipad相机配合使用的HTML应用程序,并将拍摄的图像上传到我的服务器。 n当上传图像时,使用imagecopy()获取水印。 p>
当我在计算机上测试时,一切正常,但出于某种原因,如果我在ipad上拍照/ ipod / iphone在纵向中,带有水印的图像旋转到横向模式。 p>
为了澄清:原始图片正确上传,带有水印的图像被旋转。 当我在带有肖像图像的计算机上尝试时,这不会发生。 p>
这是一些代码,如果有帮助(我使用Codeigniter框架)。 如果您需要更多代码,请问,虽然我认为上传本身没有任何问题。 p>
// imagecopy的代码会添加水印
$ overlay = imagecreatefrompng(base_url()。'assets / images / imgoverlay.png');
$ img = imagecreatefromjpeg(base_url()。'uploads /'。$ config ['file_name']);
$ imageSize = getimagesize(base_url()。'uploads /'。$ config ['file_name']);
$ sx = imagesx($ overlay);
$ sy = imagesy($ overlay);
$ newWatermarkWidth = $ imageSize [0];
$ newWatermarkHeight = $ sy * $ newWatermarkWidth / $ sx;
$ test = imagecopy(
$ img,
$ overlay,
$ imageSize [0] / 2 - $ newWatermarkWidth / 2,
$ imageSize [1] - $ newWatermarkHeight,
0,
0,
imagesx($ img),imagesy($ img)
);
code> pre> \ n
非常感谢! p>
div>
I'd guess this is related to this question: Generated images showing flipped
The iPad camera probably just stores the image in the same way, regardless of device orientation, and instead writes an Exif tag to make sure it's properly rotated when displayed.
Are you sure the image is not rotated? Most viewers automatically rotates the image for you, so you will never see this on your computer.
Try this:
$exif = exif_read_data('test.jpg');
if(isset($exif['Orientation'])) {
if($exif['Orientation'] === 1) print 'rotated clockwise by 0 deg (nothing)';
if($exif['Orientation'] === 8) print 'rotated clockwise by 90 deg';
if($exif['Orientation'] === 3) print 'rotated clockwise by 180 deg';
if($exif['Orientation'] === 6) print 'rotated clockwise by 270 deg';
if($exif['Orientation'] === 2) print 'vertical flip, rotated clockwise by 0 deg';
if($exif['Orientation'] === 7) print 'vertical flip, rotated clockwise by 90 deg';
if($exif['Orientation'] === 4) print 'vertical flip, rotated clockwise by 180 deg';
if($exif['Orientation'] === 5) print 'vertical flip, rotated clockwise by 270 deg';
}