note 117748 added to function.imagecolorat

From: Date: Fri, 31 Jul 2015 18:54:36 +0000
Subject: note 117748 added to function.imagecolorat
Groups: php.notes 
Request: Send a blank email to php-notes+get-203239@lists.php.net to get a copy of this message
So I have written the most pointless use I could think of for this function (imagecolorat). Basically it converts every pixel in the given image for an <i> tag. You can set the rendered pixel size with $p <?php $p = 4; // Set pixel width/height ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Image to DOM</title> <style> .canvas {position: relative;} .pixel {width: <?= 1*$p; ?>px; height: <?= 1*$p; ?>px; position: absolute; display: block;} </style> </head> <body> <form action="/" method="post" enctype="multipart/form-data"> <input type="file" name="image"> <input type="submit"> </form> <?php if ($_FILES) { $post_img = $_FILES['image']; $filename = $post_img['name']; $tmp_img = $post_img['tmp_name']; if(preg_match('/[.](jpg)$/', $filename)) { $img = imagecreatefromjpeg($tmp_img); } else if (preg_match('/[.](gif)$/', $filename)) { $img = imagecreatefromgif($tmp_img); } else if (preg_match('/[.](png)$/', $filename)) { $img = imagecreatefrompng($tmp_img); } list($width, $height) = getimagesize($tmp_img); echo '<div class="canvas" style="width: '.$width*$p.'px; height: '.$height*$p.'px;">'; for ($i = 0; $i < $height; $i++) { $y = $i; // Get Y coords for ($j = 0; $j < $width; $j++) { $x = $j; // Get X coords $rgb = imagecolorat($img, $x, $y); // Get pixel color $rgba = imagecolorsforindex($img, $rgb); unset($rgba['alpha']); // Remove Alpha channel $bg_color = implode(', ', $rgba); ?> <i class="pixel" style="background: rgb(<?= $bg_color; ?>); top: <?= $i*$p; ?>px; left: <?= $j*$p; ?>px;"></i> <?php } } echo '</div>'; } ?> </body> </html> ---- Server IP: 72.52.91.14 Probable Submitter: 87.112.233.176 ---- Manual Page -- http://php.net/manual/en/function.imagecolorat.php Edit -- https://master.php.net/note/edit/117748 Del: integrated -- https://master.php.net/note/delete/117748/integrated Del: useless -- https://master.php.net/note/delete/117748/useless Del: bad code -- https://master.php.net/note/delete/117748/bad+code Del: spam -- https://master.php.net/note/delete/117748/spam Del: non-english -- https://master.php.net/note/delete/117748/non-english Del: in docs -- https://master.php.net/note/delete/117748/in+docs Del: other reasons-- https://master.php.net/note/delete/117748 Reject -- https://master.php.net/note/reject/117748 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203239) next »