我正在尝试使用php imagerotate函数旋转图像,但它不起作用。GD图书馆也在运行。
我试过这个,
public function rotate()
{
$targ_w = 240;
$targ_h = 180;
$jpeg_quality = 100;
$degrees = 90;
$src = "/photos/sunset.jpg";
$image = imagecreatefromjpeg($src);
$rotatedImage = imagerotate($image,$degrees,0);
imagejpeg( $rotatedImage,$src,$jpeg_quality);
imagedestroy($rotatedImage);
die();
}发布于 2013-10-10 12:19:59
您正在输出未更改的 $image文件。你应该输出旋转的。
imagejpeg( $rotatedImage,$name ,$jpeg_quality);第二件事-你的形象是空的。它只定义了宽度和高度,但里面没有内容。您定义了一个$src变量,但根本不使用它。
也许您想用以下内容替换imagecreatetruecolor:
$src = "/photos/sunset.jpg";
$image = imagecreatefromjpeg($src);发布于 2014-02-18 17:09:18
<?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);
// Free the memory
imagedestroy($source);
imagedestroy($rotate);
?>发布于 2013-10-10 12:19:20
必须输出旋转图像(传递$rotatedImage而不是$image):
$rotatedImage = imagerotate($image,$degrees,0);
header('Content-type: image/jpeg'); //Header is required to output the image.
imagejpeg($rotatedImage,$name ,$jpeg_quality);
imagedestroy($rotatedImage);
die();https://stackoverflow.com/questions/19295438
复制相似问题