[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Any way to get background color info using JavaScript?

Posted on 2004-10-29
Medium Priority
Last Modified: 2008-03-17
I know you can get a GIF's height and width, but I'm
wondering if there's anyway to retrieve its background
color. From what I understand, it's stored in the GIF
header right along with the height & width information,
so I'm curious if it's possible.

Failing that, is there anyway to dynamically rename a
GIF to a different file. In other words, can you change
the name of "image.gif" to "image.txt" somehow? If
so, you could just pull in the text file and read the
background color info. But I can't figure out how to do
that either!

Any suggestions are welcome
Question by:sleepybear
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Author Comment

ID: 12445045
Oops. I suppose I should have mentioned that I meant to
add... "any way to do this in JavaScript?"

Hopefully, since this IS in the JavasScript section you guys
figured that out.
LVL 31

Accepted Solution

GwynforWeb earned 531 total points
ID: 12445155
not client side. The only things exposed off the header of an image file to JS are the heigth and width. see http://www.devguru.com/Technologies/ecmascript/quickref/image.html

You can not change the extension using JS programatically
LVL 31

Expert Comment

ID: 12457539
     You have access to 4 bytes of info in the header (ie height and width) this is 32 bits. By limiting your chars to alpha-numeric and a just a few special chars with  compression you can get it down to between 4 and 5 bits per char (if you are really smart with the compression depending on the message type you could even get this down lower). Bascially you are looking at about 6 or 7 chars per header, this is not a lot and you would require about  40 images for 256 chars.

LVL 31

Expert Comment

ID: 12460396
the width and height in the header can be edited with a hex editor on say with a 3 by 3 .bmp to be 63000 by 45987 and the file will still be tiny, the file can be loaded and not displayed with the data extracted, I tried it.  But still not much data per image.

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question