我想要一个用户能够永久旋转顺时针或逆时针的图像文件。我试过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>";发布于 2012-09-22 14:25:58
使用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使用它
发布于 2012-09-22 14:29:40
如果你想永久旋转你的图片,HTML或CSS是不合适的。您将需要一些服务器端脚本来存储旋转后的图片。
你应该看看GD library。对于这种图像操作,我一直在使用Imagine library,这是一个基于GD的库。
发布于 2016-01-28 07:59:31
如果别人需要这个的话。以下是一个函数,它将用旋转后的图像替换原始图像:
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);
}
} https://stackoverflow.com/questions/12541290
复制相似问题