473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Jpeg to HTML

Hi guys,

I was thinking.. wouldn't it be cool if you could take an image (jpeg) and
redraw the entire thing in HTML ? In theory you could parse the image to
create an array containing the RGB value for every pixel and then print this
out as a series of 1 pixel wide DIV's with the background color set to the
pixel colour.

I realise this would result in a massive document (likely several mb) with
millions of layers, but has anyone ever tried something like this ? I know
you can get programs to convert jpeg to ascii art, so I can't be too far off
in my thinking..

Regards,
Chris
Jun 3 '07 #1
8 5404
On Jun 3, 6:04 pm, "Skeleton Man" <inva...@guestwho.comwrote:
Hi guys,

I was thinking.. wouldn't it be cool if you could take an image (jpeg) and
redraw the entire thing in HTML ? In theory you could parse the image to
create an array containing the RGB value for every pixel and then print this
out as a series of 1 pixel wide DIV's with the background color set to the
pixel colour.

I realise this would result in a massive document (likely several mb) with
millions of layers, but has anyone ever tried something like this ? I know
you can get programs to convert jpeg to ascii art, so I can't be too far off
in my thinking..

Regards,
Chris
What would the practical value of such a thing be?

Jun 3 '07 #2
On Sun, 3 Jun 2007 18:04:03 -0400, "Skeleton Man" <in*****@guestwho.comwrote:
>I was thinking.. wouldn't it be cool if you could take an image (jpeg) and
redraw the entire thing in HTML ? In theory you could parse the image to
create an array containing the RGB value for every pixel and then print this
out as a series of 1 pixel wide DIV's with the background color set to the
pixel colour.

I realise this would result in a massive document (likely several mb) with
millions of layers, but has anyone ever tried something like this ? I know
you can get programs to convert jpeg to ascii art, so I can't be too far off
in my thinking..
Yes, been done before, one of many examples:
http://www.eggheadcafe.com/articles/...l/default.aspx

It's a fairly pointless exercise though.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jun 3 '07 #3
On Jun 3, 6:52 pm, Andy Hassall <a...@andyh.co.ukwrote:
On Sun, 3 Jun 2007 18:04:03 -0400, "Skeleton Man" <inva...@guestwho.comwrote:
I was thinking.. wouldn't it be cool if you could take an image (jpeg) and
redraw the entire thing in HTML ? In theory you could parse the image to
create an array containing the RGB value for every pixel and then print this
out as a series of 1 pixel wide DIV's with the background color set to the
pixel colour.
I realise this would result in a massive document (likely several mb) with
millions of layers, but has anyone ever tried something like this ? I know
you can get programs to convert jpeg to ascii art, so I can't be too far off
in my thinking..

Yes, been done before, one of many examples:http://www.eggheadcafe.com/articles/...l/default.aspx

It's a fairly pointless exercise though.

--
Andy Hassall :: a...@andyh.co.uk ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool
Pretty pointless and really not that difficult, either:

function imageToHTML($img) {
$width = imagesx($img);
$height = imagesy($img);

for($i = 0; $i < $height; $i++) {
for($j = 0; $j < $width; $j++) {
$color = str_pad(base_convert(imagecolorat($img, $j, $i),
10, 16), 6, '0', STR_PAD_LEFT);
echo '<div style="position: absolute; background-color:
#' . $color . '; height: 1px; width: 1px; top: ' . $i . 'px; left: ' .
$j . 'px;"></div>' . "\n";
}
}
}

Jun 3 '07 #4
ZeldorBlat wrote:
On Jun 3, 6:52 pm, Andy Hassall <a...@andyh.co.ukwrote:
>On Sun, 3 Jun 2007 18:04:03 -0400, "Skeleton Man" <inva...@guestwho.comwrote:
>>I was thinking.. wouldn't it be cool if you could take an image (jpeg) and
redraw the entire thing in HTML ? In theory you could parse the image to
create an array containing the RGB value for every pixel and then print this
out as a series of 1 pixel wide DIV's with the background color set to the
pixel colour.
I realise this would result in a massive document (likely several mb) with
millions of layers, but has anyone ever tried something like this ? I know
you can get programs to convert jpeg to ascii art, so I can't be too far off
in my thinking..
Yes, been done before, one of many examples:http://www.eggheadcafe.com/articles/...l/default.aspx

It's a fairly pointless exercise though.

--
Andy Hassall :: a...@andyh.co.uk ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool

Pretty pointless and really not that difficult, either:

function imageToHTML($img) {
$width = imagesx($img);
$height = imagesy($img);

for($i = 0; $i < $height; $i++) {
for($j = 0; $j < $width; $j++) {
$color = str_pad(base_convert(imagecolorat($img, $j, $i),
10, 16), 6, '0', STR_PAD_LEFT);
echo '<div style="position: absolute; background-color:
#' . $color . '; height: 1px; width: 1px; top: ' . $i . 'px; left: ' .
$j . 'px;"></div>' . "\n";
}
}
}
Would that function be limited to an instance where an image was created
or is it possible to use imagecreatefrompng()?

Granted, I know very little about image-related PHP. I thought I could
plug in a PNG I had (just to get a valid image resource) and I did
nothing, but crash my browser *every* time.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 4 '07 #5
-Lost wrote:
ZeldorBlat wrote:
>Pretty pointless and really not that difficult, either:

function imageToHTML($img) {
$width = imagesx($img);
$height = imagesy($img);

for($i = 0; $i < $height; $i++) {
for($j = 0; $j < $width; $j++) {
$color = str_pad(base_convert(imagecolorat($img, $j, $i),
10, 16), 6, '0', STR_PAD_LEFT);
echo '<div style="position: absolute; background-color:
#' . $color . '; height: 1px; width: 1px; top: ' . $i . 'px; left: ' .
$j . 'px;"></div>' . "\n";
}
}
}

Would that function be limited to an instance where an image was created
or is it possible to use imagecreatefrompng()?

Granted, I know very little about image-related PHP. I thought I could
plug in a PNG I had (just to get a valid image resource) and I did
nothing, but crash my browser *every* time.
I played with it a bit more and I see now that it merely sent too much
information to the browser. I had a fairly small image (300x30) and it
sent almost 10,000 lines of DIVs to the client-side.

Anyway, now that I see it works. How come it does not display the
images correctly?

If I look close I can see my image amongst a predominantly black square.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 4 '07 #6
Skeleton Man kirjoitti:
Hi guys,

I was thinking.. wouldn't it be cool if you could take an image (jpeg) and
redraw the entire thing in HTML ? In theory you could parse the image to
create an array containing the RGB value for every pixel and then print this
out as a series of 1 pixel wide DIV's with the background color set to the
pixel colour.

I realise this would result in a massive document (likely several mb) with
millions of layers, but has anyone ever tried something like this ? I know
you can get programs to convert jpeg to ascii art, so I can't be too far off
in my thinking..
Reminds me of something I did a year ago or so. I made my own version of
the classic mosaic image thingy where smaller images make a bigger
picture. I took a bunch of pictures, clearly I would've needed a whole
lotta more of them, but they did it for the test. I shrunk the images to
very small size, 16x16 to keep it simple, then took an approximation of
the images color and stored them as "colors", as in one image would
represent a particular color. Next I just uploaded a random image,
resized it to 16x16 and took the closest color to each pixels and used
the cloesest matching image to display it. so in the end I had 16x16
grid of images in an html table, which somewhat resembled the original
image. It wasn't perfect, but with lots of more pictures it and a bigger
grid it would've worked... :) But as an experiment it was super cool!

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Jun 4 '07 #7
Thanks guys.. didn't figure it was an original idea.. and as for pratical
use/value, none whatsoever.. purely entertainment value..

Chris
Jun 4 '07 #8
At Mon, 04 Jun 2007 19:49:42 -0400, Skeleton Man let h(is|er) monkeys
type:
Thanks guys.. didn't figure it was an original idea.. and as for pratical
use/value, none whatsoever.. purely entertainment value..

Chris
It's a pity these html reprentations don't scale proportionally when
resizing the font in a page. That would have added some value
to the technique.

--
Schraalhans Keukenmeester - sc*********@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Jun 6 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: UnixUser | last post by:
I have a jpeg file and a HTML page that are stored in two separate blob fields of a databses, namely interbase, what is the best method of pulling each of these items out so that they can be...
1
by: Derek | last post by:
I wanted to know if anyone had any insight or sample code of creating an AVI file from a directory of JPEG images. I have read the thread that that speaks about creating a MOV file from JPEG images...
3
by: bull.enteract | last post by:
Ok, I start off with a bitmap image. I encode it as a jpeg and send it across the network and pick it up on the other end. Now I have the jpeg image on the other end as an arrray of bytes and I...
9
by: Tim | last post by:
Since rtf files cause so many troubles, i.e., allow the users to download the files, slow loading, incompatible with other browser, and so on. Do you think I should convert them to JPEG files to...
0
by: Jack Wu | last post by:
Hi I've spent a good majority of my day trying to figure out how to have PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I have not gotten anywhere. Could somebody please...
15
redvi4
by: redvi4 | last post by:
Hello Friends THis is my first Post i like to program on php/unix, perl But at this time i have a question. i want to make an .exe program that make only 1 action or work: read a JPEG...
1
by: alcool | last post by:
Hi, I would like use a socket for write a file jpeg on the network. In others words, it is possible to publish a jpeg (like a streamer) that a client can fetch and view? file JPEG -socket that...
4
by: Pacino | last post by:
Hi, everyone, I am wondering whether it's possible to read part (e.g. 1000*1000) of a huge jpeg file (e.g. 30000*30000) and save it to another jpeg file by pure python. I failed to read the...
0
by: =?Utf-8?B?TWFyazEyMw==?= | last post by:
I have two pieces of VB.NET code below: a) Sends an email b) Returns a programmatically created jpeg image to a webpage. How can I embed the programmatically created jpeg into an HTML...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.