3

我希望用户能够顺时针或逆时针永久旋转图像文件。我已经尝试过 imagejpeg($rotate) 但似乎无法使其正常工作。

            <form method="GET" action="rotate.php">
                Rotate:<input type="radio" name="rotate" value="clockwise">Clockwise
                <input type="radio" name="rotate" value="counterclockwise">Counter clockwise
                <input type="Submit" name="Submit1"/>
            </form>

我试图让用户能够选择单选按钮方向并单击“提交”。然后显示的图像将更新旋转到他们选择的任何方向,并在再次使用时永久保持这种状态。有什么帮助或方向吗?

    <img src=\"uploads/$user/$folder/$image\"/></a>";
4

3 回答 3

3

使用imagerotate()它将永久旋转图像。

<?php
// File and rotation
$filename = 'test.jpg';
$degrees = 180;

// Content type
header('Content-type: image/jpeg');

// Load
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

// Output
imagejpeg($rotate);
?>

http://php.net/manual/en/function.imagerotate.php

或者您可以使用 jquery 来使用它

http://www.linein.org/examples/jquery_rotate/

于 2012-09-22T06:25:57.887 回答
0

如果你想永久旋转你的图片,HTML 或 CSS 是不可行的。您将需要一些服务器端脚本来存储旋转的图片。

你应该看看GD 库。对于这种图像处理,我一直在使用Imagine library,这是一个基于 GD 的库。

于 2012-09-22T06:29:39.573 回答
0

如果其他人需要这个。这是一个将原始图像替换为旋转图像的函数:

    public function autoRatateImage($src, $exifCode = ''){

        if($exifCode == ''){
            $exif = exif_read_data($src);
        }else{
           $exif['Orientation'] = $exifCode; 
        }
        $source = imagecreatefromjpeg($src);
        if (!empty($exif['Orientation'])) {
            switch ($exif['Orientation']) {
                case 3:
                    $image = imagerotate($source, 180, 0);
                    break;

                case 6:
                    $image = imagerotate($source, -90, 0);
                    break;

                case 8:
                    $image = imagerotate($source, 90, 0);
                    break;
            }
            if (file_exists($src)) {
                unlink($src);
            }
            imagejpeg($image, $src , 100);  
        } 

    } 
于 2016-01-27T23:59:30.603 回答