[英]php imagejpeg()
我正在尝试在我的网站上放置一个rotate img函数。 我正在使用imagejpeg(),但返回的是满是乱码的垃圾。 你能解释为什么吗?
if ($_GET["rotate"] == "clockwise")
{
$degrees = 90;
// Content type
//header('Content-type: image/jpeg');
// Load
$source = imagecreatefromjpeg($path);
// Rotate
$rotate = imagerotate($source, $degrees, 0);
// Output
if (imagejpeg($rotate))
echo "Your image has been rotated clockwise";
}
if ($_GET["rotate"] == "counterclockwise")
{
$degrees = 270;
// Content type
//header('Content-type: image/jpeg');
// Load
$source = imagecreatefromjpeg($path);
// Rotate
$rotate = imagerotate($source, $degrees, 0);
// Output
if (imagejpeg($rotate))
echo "Your image has been rotated Counterclockwise";
}
?>
它将粘贴到页面上:
创建者:gd-jpeg v1.0(使用IJG JPEG v62),默认质量为C $。 “,#(7),01444'9 = 82 <.342ÿÛC2 !!22222222222222222222222222222222222222222222ÿ 1AQaq“2B'¡±Á#3RðbrÑON $4á(AND很长的路要走)
如果我也将其更改为顺时针方向,则乱码也将发生变化,因此我认为它在某种程度上起作用,但并不是从中创建jpg。 任何帮助都是极好的。
那就是形象。 您只是没有告诉浏览器它是什么,浏览器将数据解释为文本。 设置标题以告诉您的浏览器将数据解释为图像:
header('Content-Type: image/jpeg');
图像数据将必须是页面上唯一的输出,之前或之后必须没有其他HTML或文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.