輸出 JPEG 圖像
<?php
// 創鍵空白圖像並添加一些文本
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// 設置內容類型標頭 —— 這個例子里是 image/jpeg
header('Content-Type: image/jpeg');
// 輸出圖像
imagejpeg($im);
// 釋放內存
imagedestroy($im);
?>
保存一副 JPEG 圖像
<?php
// 創鍵空白圖像並添加一些文本
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// 保存圖像為 'simpletext.jpg'
imagejpeg($im, 'simpletext.jpg');
// 釋放內存
imagedestroy($im);
?>
以 75% 的圖像質量輸出圖像
<?php
// 創鍵空白圖像並添加一些文本
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// 設置內容類型標頭 —— 這個例子里是 image/jpeg
header('Content-Type: image/jpeg');
// 使用 NULL 跳過 filename 參數,並設置圖像質量為 75%
imagejpeg($im, NULL, 75);
// 釋放內存
imagedestroy($im);
?>