This article mainly introduces the specific steps of creating images in PHP. Has very good reference value. Let’s take a look at it with the editor.
PHP image processing is the most common in verification codes. Let’s talk about the specific steps of using PHP to create images.
Brief description: PHP is not limited to creating HTML output, it can also create and process items including GIF, PNG (recommended), JPEG, WBMP and Images in various formats including XPM . Even more conveniently, PHP can directly output the image data stream to the browser. To use image processing functions in PHP, you need to compile PHP with the GD library. The GD library and PHP may require other libraries, depending on the image format you want to process.
You can use the image functions in PHP to obtain images in the following formats: JPEG, GIF, PNG (recommended: the image created will not lose its stitching), SWF, TIFF and JPEG2000.
Step instructions: Please check the php manual for specific function description
<?php //第一:设定标头,告诉浏览器你要生成的MIME 类型 header("Content-type: image/png"); //第二:创建一个画布,以后的操作都将基于此画布区域 $codew = 100; $codeh = 60; $codeimg = imagecreatetruecolor($codew, $codeh); //获取画布颜色 $red = imagecolorallocate($codeimg, 255, 0, 0); $white = imagecolorallocate($codeimg, 255, 255, 255); $green = imagecolorallocate($codeimg, 75, 222, 26); //第三:填充画布背景颜色 imagefill($codeimg, 0, 0, $red); //第四:绘制线条 + 填充文字... imageline($codeimg, 0, 00, 30, 60, $white); imageline($codeimg, 0, 00, 50, 60, $white); imageline($codeimg, 0, 00, 80, 60, $white); //填充文字 imagestring($codeimg, 10, 30, 30, "qwe4", $green); //第五:输出创建的画布 imagepng($codeimg); //第六:销毁画布 imagedestroy($codeimg); ?>
## Effect View
The above is the entire content of this article, I hope it will be helpful to everyone's study. Detailed explanation of how PHP uses imagick extension to merge images
phpImageVerification code generation code_php skills
Imageprocessing
The above is the detailed content of Specific steps to create images in php. For more information, please follow other related articles on the PHP Chinese website!