Home > Backend Development > PHP Tutorial > Convert php images to ascii output images_PHP tutorial

Convert php images to ascii output images_PHP tutorial

WBOY
Release: 2016-07-20 11:06:58
Original
995 people have browsed it

php Convert image to ascii Output image

php Convert image to ascii Output image

This PHP function creates a simple ASCII artistic rendering of a JPG image. It uses Guangdong to do the heavy lifting, and some simple shifting to assign colors. The color is then transferred to a hexadecimal value and the resulting text is output to the browser. ASCII from Image Arts with PHP is now easy. If you feel you have any improvements, please feel free to contact us with your ideas for PHPRO.


function image2ascii( $image )
{
// return value
$ret = '';

// open the image
$img = ImageCreateFromJpeg($image);

// get width and height
$width = imagesx($img);
$height = imagesy( $img);

// loop for height
for($h=0;$h<$height;$h++)
{
// loop for height
for ($w=0;$w<=$width;$w++)
                                                                                                                               = ($rgb >> 16) & 0xFF; value from the rgb
$hex = '#'.str_pad(dechex($r), 2, '0', STR_PAD_LEFT).str_pad(dechex($g), 2, '0', STR_PAD_LEFT).str_pad( dechex($b), 2, '0', STR_PAD_LEFT);

// now add to the return string and we are done
if($w == $width)
🎜>                                             . '; 🎜>
// an image to convert

$image = 'test.jpg';


// do the conversion
$ascii = image2ascii( $ image );

// and show the world
echo $ascii;
?>





http://www.bkjia.com/PHPjc/444992.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/444992.html


TechArticle

php Convert image to ascii Output image php Convert image to ascii Output image This PHP function creates a simple JPG image ASCII artistic rendering. It uses Canton to do the heavy lifting, and...



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template