php縮圖的有關問題

來源:互聯網
上載者:User
php縮圖的問題
以下是My Code:

1.2.$ef='index\images\m_1307414811439.jpg';
3.$bs="";
4.$rr=getimagesize($ef);
5.$new=imagecreatetruecolor(300,300);
6.imagecopyresized($new,$bs,0,0,0,0,300,300,$rr[0],$rr[1]);
7.header("content-type:image/jpeg");
8.imagejpeg($new);
9.?>

出現的問題是6,7行報錯,還有亂碼

Warning: imagecopyresized(): supplied argument is not a valid Image resource in D:\PHP\r.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at D:\PHP\r.php:6) in D:\PHP\r.php on line 7
????JFIF??>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ??C $.' ",#(7),01444'9=82<.342??C 2!!22222222222222222222222222222222222222222222222222??,,"?? ???}!1AQa"q2亼?#B繃R佯$3br? %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz儎厗噲墛挀敃枟槞殺¥ウЖ┆渤吹鬥腹郝媚牌僑墒矣哉腫剄巹懺溴驍栝強蝮趲鱝??? ???w!1AQaq"2?B憽繃#3R?br? $4?%?&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz們剠唶垑姃摂晼棙櫄ⅲぅΗī炒刀犯購旅呐魄壬室釉罩棕仝懺溴驍栝牝篝貊鼬????(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(??(?

------解決方案--------------------
imagecopyresized函數的前兩個參數要求是繪圖物件變數,不是檔案名稱路徑字串之類的東西,你第2個參數傳的是$bs,然而你前面把它賦值為字串內容,所以出錯
我隨便修了下代碼,你看著思考吧


$ef='1.jpg';
$bs=imagecreatefromjpeg($ef);
$rr=getimagesize($ef);
$new=imagecreatetruecolor(300,300);
imagecopyresized($new,$bs,0,0,0,0,300,300,$rr[0],$rr[1]);
header("content-type:image/jpeg");
imagejpeg($new);
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.