我正在尝试在我的网站上放置一个旋转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";
}
?>
将其粘贴到页面上:
ÿØÿàJFIFÿþ> CREATOR:gd-jpeg v1.0(使用IJG JPEG v62),默认质量ÿÛC$。 “,#(7),01444'9 = 82<.342ÿÛC2!! 22222222222222222222222222222222182”1AÄÿÄμ}!1AQa“q2'¡#B±ÁRÑð$ 3br,%&'()* 456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ”...†‡ ‰“'”“• - 〜™¢¢¥|§¨²²³μμ·····································································································一个长路)
如果我将其改为顺时针方向,那么乱码也会发生变化,所以我认为它在某种程度上有效,但它并没有从中创造出一个jpg。任何帮助都是极好的。
答案 0 :(得分:8)
图像。您只是不告诉浏览器它是,您的浏览器将数据解释为文本。设置标题以告知浏览器将数据解释为图像:
header('Content-Type: image/jpeg');
图像数据必须是页面上输出的唯一内容,而不是其他HTML或文本之前或之后。