【问题标题】:php imagejpeg()php imagejpeg()
【发布时间】:2012-09-21 08:04:27
【问题描述】:

我正在尝试在我的网站上添加旋转 img 功能。我正在使用 imagejpeg() 但它返回一个充满胡言乱语的 sloo。你能解释一下为什么吗?

                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ÿþ>创建者:gd-jpeg v1.0(使用 IJG JPEG v62),默认质量 ÿÛC $。 ",#(7),01444'9=82<.342 on and for a>

如果我将其更改为顺时针,乱码也会发生变化,所以我认为它有点工作,但它不会从中创建 jpg。任何帮助都是极好的。

【问题讨论】:

  • 在输出前添加:header('content-type:image/jpeg')。

标签: php


【解决方案1】:

图像。您只是没有告诉您的浏览器它是,您的浏览器将数据解释为文本。设置一个标题来告诉您的浏览器将数据解释为图像:

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

图像数据必须是页面上唯一输出的内容,之前或之后没有其他 HTML 或文本。

【讨论】:

  • 谢谢。如果我想永久更改图像文件的方向,那不是要使用的功能吗?
  • 是的。你对结果所做的显然是错误的。您可能希望将结果保存回文件。
猜你喜欢
  • 1970-01-01
  • 2010-12-06
  • 1970-01-01
  • 2021-08-14
  • 2018-07-14
  • 1970-01-01
  • 2018-07-19
  • 2013-06-04
  • 2013-10-29
相关资源
最近更新 更多