Jump to content

Converting a image into a Excel doc(Source code)

well heres the best way of explaining this i had found it on youtube by Matt Parker(heres the vid https://www.youtube.com/watch?v=UBX2QQHlQ_I) he also has a website you can do it on but i am looking for the source code i dont care what language its in , I could not find it for the life of me (yes i tried to google) pls dont roast me if you find it on google lol.....thanks:)

Link to post
Share on other sites

sorry my bad i meant image but my laziness got the better of me and he is not a comedian he is a mathematician and also has written a couple of books so yea lol sorry about that

now ive changed the title to image so that should explain it a bit better

Link to post
Share on other sites

So if I understand correctly, what you want is basically to take an image and convert it into a spreadsheet where for each pixel of the image, you have three cells, and each of those 3 cells has the background color of that pixel (red , green and blue).

 

You can probably generate such a spreadsheet, it's not hard. For example, with about 10 lines of code in PHP, I can load a JPG or PNG picture in memory and access each pixel and determine the amount of red, green and blue.

 

The problem is most spreadsheet files (like ODS for OpenOffice/LibreOffice or xls are very complex file formats)... and they're not optimized for information about colors and crap. 

In order to specify the background color you have to create a style for the cell, and that's defined sort o like this:

 

<style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default">
  <style:table-cell-properties fo:background-color="#000080" />
</style:style>

this basically defines cell style called "ce2" which tells the software to apply that background color ... so you have about 170 bytes to define a style.

Then, a cell would be defined in the spreadsheet something like this:

 

<table:table-column table:style-name="co1" table:default-cell-style-name="ce2" />

pretty much another 80 bytes... so overall, you have 250 bytes for one cell.

 

So, if you have a 1920x1080 pixels with around 100 000 unique colors, your spreadsheet file will be at least   1920x1080x3x80 bytes = 497,664,000 bytes , plus maybe around 0.2 MB to define the background colors (3x255 unique background colors x 180 bytes)  ... so probably a 500-600 MB spreadsheet, before it's compressed.

 

My guess is that software like excel would crash and software like LibreOffice would probably take hours to load.

 

My guess is that in that video , the guy resized the image to something like 320x240 or 480x360 and that gave him a reasonably small spreadsheet.

or maybe he just faked the spreadsheet layout by laying a picture where the cells would actually be in that picture.

 

// he says somewhere in the video that the spreadshet is about 1000 by 300 cells, so he plays with around 300x300 pixel image or something like that

Link to post
Share on other sites

Yep awesome he even has a website where you can turn a image into a spreadsheet and he also mentioned the he had written a python code that could do it but couldnt find that either but yea that gave me a general idea of what i am looking at i just had to get my head around it

Link to post
Share on other sites

btw you should know that he oversimplifies things.

not all LCD displays have the cells of same size and some don't arrange the cells vertically, one under the other one. Some LCD displays actually use 4 elements, red green blue and white.. 

The human eye is more sensitive to green compared to the other colors so sometimes the green uses less space on the actual lcd screen compared to other cells.

 

See this : https://www.extremetech.com/computing/122725-what-the-ipad-3s-retina-display-looks-like-under-a-microscope

 

check the picture for google nexus to see what i mean about the 3 elements not being in straight line all the time.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×