簡體   English   中英

php imagejpeg()

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM