Date
Oct. 18th, 2024
 
2024年 9月 16日

Post: PHP Primer 025 : 图像处理(三)

Today is the A Memorial Day

PHP Primer 025 : 图像处理(三)

Published 12:02 Feb 02, 2012.

Created by @ezra. Categorized in #Programming, and tagged as #PHP.

Source format: Markdown

Table of Content

通过前面的学习,已经可以成功在浏览器上输出图像,那么问题来了,如何保输出为文件呢?

<?php
$img = imagecreatetruecolor(100, 100);
$red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
imagestring($img, 5, 0, 0, "Hello, world", $red);
header("content-type: image/png");
$filenamePNG = "myImg.png";
// 输出 PNG 文件,额外设置文件名
imagepng($img, $filenamePNG);
$filenameJPG = 'myImg.jpg';
// 输出 JPG 文件,额外设置文件名、压缩质量
​imagejpeg($img, $filenameJPG, 90);
imagedestroy($img);
?>
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询