2011-12-12 99 views
3

我使用流行的timthumb.php來調整圖像大小。我是能夠成功地改變高度和圖像的寬度,但每當我做「另存爲」默認保存爲PHP ..如何將圖像保存爲jpg或png使用timthumb.php調整大小API

例如,如果您嘗試保存出席 http://www.binarymoon.co.uk/demo/timthumb-basic/timthumb.php?src=castle1.jpg&w=400圖像保存爲一個文件帶有擴展名..

我該如何強制將它保存爲png/jpg?我知道MIME類型是圖像/ JPG或圖像/ PNG ....所有我想要的圖像應保存爲PNG或JPG默認情況下...請幫助

+0

什麼瀏覽器? Chrome嘗試將其保存爲JPEG圖像。 – Krzysztof

回答

0

未經測試,但您可以添加一個額外的標題行1195下:

header('Content-Length: ' . filesize($file)); 
header('Content-Disposition: attachment; filename="' . basename($file) . '";'); 
0

我只是從這個URL http://timthumb.googlecode.com/svn/trunk/timthumb.php 使用timthumb.php,當我點擊另存爲,默認的文件名是「Imagename.php.jpeg」。並且可以在「.jpeg」之前更改名稱。可能這會幫助你。

我在ubuntu 10.4上使用Firefox。

享受

1

Timthumb沒有「另存爲」選項(在開發者博客http://www.binarymoon.co.uk/2010/11/timthumb-hints-tips/這個答覆http://o7.no/biJTYD)。 Timthumbs使用與源圖像相同的格式保存處理後的圖像。

當source是「png」時,我成功地強制「另存爲jpg」,並在下方做了一些工作(在742行附近)。您可以安排在if-then-else鏈上工作的其他轉換。

if(preg_match('/^image\/(?:jpg|jpeg)$/i', $mimeType)){ 
     $imgType = 'jpg'; 
     imagejpeg($canvas, $tempfile, $quality); 
} else if(preg_match('/^image\/png$/i', $mimeType)){ 
     // ***************WORKAROUND STARTS HERE**************** 
     //$imgType = 'png'; 
     //imagepng($canvas, $tempfile, floor($quality * 0.09)); 
     $imgType = 'jpg'; 
     imagejpeg($canvas, $tempfile, $quality); 
相關問題