This is probably done a thousand times before, so this is the 1001st
Use this as a CGI, upload an image and get it back displayed as an HTML table. (not sure why you wanna do such a thing though ;)
View a live version here
Update: I fixed the code which now uses snippets from merlyn's column.#!/usr/bin/perl -Tw use strict; $|++; use CGI qw/:standard *table/; $CGI::POST_MAX = 200000; # it's already too heavy print header, start_html('Image2HTML'); print h1 ('Image2HTML'); if (param('do')) { eval "use Image::Magick"; die "We need Image::Magick: $@\n" if $@; my $image; my $file = upload('file'); $image = Image::Magick->new or die "Cannot create Image::Magick Object: $image\n"; my $error = $image->Read(file=>$file); if ($error) { print strong('Bad File: '. $error ); } else { $image->Set(magick => 'rgb') && die "Cannot set to RGB, $_"; $image->Scale(geometry => '50x50'); my $width = $image->Get('columns'); my $height = $image->Get('rows'); print start_table({-border=>0, -cellpadding=>0, -cellspacing=>0}); my @blobs = unpack "C*", $image->ImageToBlob(); for (1..$height) { print q|<tr>|; for (1..$width) { print q|<td bgcolor="#|; my ($r,$g,$b) = splice @blobs, 0, 3; print sprintf("%02x%02x%02x", $r, $g, $b); print q|"><img src="/data/trans.gif" width="5" + height="5" /></td>|; } print qq|</tr>\n|; } print end_table; } } print hr; print p(q|This is Image2HTML, just another way to waste computer resources. Use the file field to upload an image (maximum size 200,000 bytes) and get it back as colored HTML <table>. Any kind of image will mostly work.|); print p(q|Note: The image is scaled down/up(?) for your own interest ; +)|); print p(q|This works best with images that have smooth color changes and gradients, brisk turns in colors can come out ugly.|); print start_form('POST', CGI::url(), 'multipart/form-data'); print filefield('file'), submit('do', 'Upload'), br; print end_form, end_html;
In reply to Image2HTML by Chady
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |