Solved

Any way to get background color info using JavaScript?

Posted on 2004-10-29
155 Views
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
0
Question by:sleepybear
    4 Comments
     

    Author Comment

    by:sleepybear
    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.
    0
     
    LVL 31

    Accepted Solution

    by:
    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
    0
     
    LVL 31

    Expert Comment

    by:GwynforWeb
         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.

       
    0
     
    LVL 31

    Expert Comment

    by:GwynforWeb
    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.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
    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…

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now