Iphone imagecopy rotates my image

﹥>﹥吖頭↗ 提交于 2019-12-13 21:19:40

问题


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!


回答1:


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.




回答2:


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';
}


来源:https://stackoverflow.com/questions/17217339/iphone-imagecopy-rotates-my-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!