Home
About
Color Tool
 

Share Wonders is proudly powered by WordPress
Entries (RSS) and Comments (RSS).
9 queries. 0.375 seconds.
Valid XHTML

Archive for April, 2006

A must-have Bookmark for Ubuntu Users

Friday, April 28th, 2006

Especially dapper testers:

https://launchpad.net/distros/ubuntu

If you want to build from source, the site will list the needed dependencies. Find and report bugs there. It is as necessary to look at as the Ubuntu Forums. I finally got mplayer to work and skin by using the information available here.

Getting Color Information From Images with JavaScript, PHP, and the GDLib

Sunday, April 23rd, 2006

Colr.org has the ability to generate random colors from an image that you can load. I looked at the code and wondered why only one hundred randomly selected colors were loaded into the script, and I have now realized why.

There is a lot of data in image.

My own attempt at getting colors from images is a lot less random. You can hover over the image to get the color value for the pixel pointed at. It’s a nice feature, but it has draw backs. For one, it is really, really slow. Opera is the slowest and Firefox will throw ’script unresponsive’ warnings at the user (even though it’s just taking its time and will respond). Nevertheless I had fun making this. It works, and you can use it to get the RGB values from JPEG and PNG file types. It loads colors for GIF file types, but I’ve seen some inconsistency in it. There’s nothing to be done about it, I blame the GD Graphics Library, which only recently started to support gifs again.

So how do I do it? The image is loaded into PHP which uses the PHP image functions to get information for colors, including the color values for pixels. PHP records all the colors and their locations (for tens to hundreds of thousands of pixels), stores it in a string and sends it to JavaScript via AJAX. JavaScript then splits the string into several arrays, and associates rgb values with locations in a big multidimensional object. As the mouse hovers over the image, JavaScript uses onmousemove to get the X and Y position of the mouse pointer, calculates where it is above the image, and uses the location to retrieve the RGB values. JavaScript then converts the RGB values into a webcolor.

So there you go! Hopefully you’ll have some use for it. I know I will.

JavaScript and SVG

Sunday, April 23rd, 2006

Check out the following two pages. They’re an example of how JavaScript can be used to manipulate SVG. SVG are scalable vector graphics. It’s very cool!

(Note you’ll need to use Firefox or IE with the Adobe SVG Viewer plugin for you to be able to see this).

A clock SVG image that tells the time with JavaScript.

Three clickable elements in an SVG document that will change colors when you click on them. Yes, you can add events to elements in an SVG document!

I plan on doing some SVG manipulation with JavaScript too. It looks like you could do just about anything with this, perhaps even build a vector drawing application for the browser!

HOWTO: Include JavaScript Code

Sunday, April 23rd, 2006

Those familiar with PHP will know what these include functions do:
[PHP]require(’file.php’);
require_once(’file.php’);
include(’file.php’);
[/PHP]
They enable PHP programmers to include code only when needed. The benefit of using such functions is that it reduces the server load and the response time. Many web applications are thousands of lines long and to parse each of these lines whenever a request is made to the server is very inefficient.

JavaScript does not have similar functions. But it is possible to include JavaScript code only when needed by utilizing the DOM methods. I have created a JavaScript Include Test Page to show how it can be done. On this test page, there are two links. The first link tests to see if the code from script2.js is ‘included.’ The second link runs the function that will include the extra script file. Once you’ve clicked the second link, the first link will show you that you’ve included the code:
Include Test
Let me explain how it works. The HTML only links to one script file initially:
[HTML]


[/HTML]he DOM Inspector, it will show there’s only one script element attached to the head element:
DOM Inspectore Before
When you click the first link without first including the second script file you’ll see from the code it will not recognize the function, ‘is_included,’ which is declared on that file:
[js]function include_test(){
var test = typeof is_included;
if(test != ‘function’){
alert(’The code from script2.js is not included.’);
}else{
is_included();
}
return;
}[/js]
If it had been included, the ‘typeof’ statement would have returned ‘function’ but instead it returns ‘undefined.’ Once script2.js is included, it will recognize the function as in the scope chain and execute it.

So how does the include work? With the DOM element methods:
[js]scriptElement = document.createElement(’script’);
scriptElement.type = “text/javascript”;
scriptElement.src = filename;
head[0].appendChild(scriptElement);[/js]
This will create an additional script element. The src will be whatever string is within the variable ‘filename.’ In this case it is script2.js. Once the second link is clicked you can check the DOM Inspector yourself to see the extra script element has been created:
DOM Inspectore After

Here’s the code on the second file:
[js]function is_included(){
alert(’The code from script2.js is included!’);
return;
}
[/js]
You see, there’s no way that alert shown in the first image could have been called if the second file had not been incorporated into the (modest) test application.

The benefit to including JavaScript only when needed is that you’ll keep your file sizes smaller. My ColorTool is getting close to 200kb in size. I never made use of the benefit of a DOM include, and therefore it is a large load, and a strain on the server, because most people do not use all of the code available every time they visit. It is a waste of resources and sloppy design.

There’s a couple of things to remember if you decide to use this. One is, check to make sure that you have not included the extra JavaScript file already, otherwise you’ll just keep including the same file over and over again whenever the include processes is enacted. This will eat up the client’s memory. Check to make sure you haven’t included the file already. For the purposes of this test I set a global variable that I test when the include process begins:
[js] if(included == false){
scriptElement = document.createElement(’script’);
scriptElement.type = “text/javascript”;
scriptElement.src = filename;
head[0].appendChild(scriptElement);
alert(’Attempting to include script2.js..’);
included = true;
}else{
alert(”Oops! You’ve already included script2.js successfully!”);
}[/js]
The other thing to remember is that code included will not be available right away, and you should be sure to test to see if it is ready before you attempt to use it.

That’s it! I hope this helped you in your JavaScripting.

Getting Information About Governments

Tuesday, April 18th, 2006

Looking for information about world governments? Many information seekers may know of the CIA World Fact Book, and use it as a quick access information tool. It is a great resource, but there are others.

One is gazettes. Gazettes are publications by the government meant to convey information to officials or the general public. Here is an example of an Irish gazette, and here is an translated into English with Google. The type of information provided in a gazette varies. There is an online gazette databank at the University of Michigan that keeps track of online gazettes published by governments world wide. It doesn’t just provide links, but also has descriptive information such as what languages it is in and what kind of information is available in the gazette:

This website attempts to list all online government gazettes and their characteristics to aid researchers. A description of the contents and coverage are included for each gazette. Anyone wishing to do further research on foreign law will find useful resources in the bibliography.

Quite a nice resource to have handy

EmbassyWorld will help you find Embassies and Consulates from around the world.
Foreign Affairs Online is another great information tool:

[it] has been specifically designed to assist students and other individuals interested in International Relations, International Law, and U.S. Foreign Policy.

Government Publications and Maps points to accessible government documents printed by governments around the world.

The United Nations Site Index, the World Bank Countries & Regions page, and University of Arizona’s Region Specific Index are also great places for international government information.

Monday, April 17th, 2006

Not that anyone from Google may be reading this post, but you never know. There’s a lot of static thinking going on the web, and some innovative things I’ve seen in one technology could be used in other places. Here are some:

Consider allowing information seekers to reorder search results.

A search engine will provide its own highly touted ranking system, which can turn out to be the number one factor for the success of online businesses. But why provide only one set of ranking? Why not create multiple ways to rank search results, so that users can choose what’s best for them from something like a drop down box.

I’ve seen this feature on article databases, and it blew me away. How often does one create lists from a database and then allow users to resort them and order them by one or another field? I think there are two things going on when presenting search results: the creation of a list of results, and a ranking of said list. Allow users to order the search results in more ways than one after the search. Some ideas: order by links to, order by relevance, order by special magic super secret search ranking, order alphabetically?, order by traffic ranking, etc

Rank Spam

Instead of just creating a spam folder, and dropping all the suspected spam into it, rank the spam from ‘more likely to be spam’ to ‘less likely to be spam’ with either colors, or text size of the subject or something similar.

It’s painful to have to go look at the spam folder and browse through offensively titled emails, and only 99% of the time find nothing, but that 1% of the time it is an email that mistakenly was labeled as spam that you cannot miss or else your career is over. I don’t think it would be an impossibility to let users know what the spam ranking of an email is and then let them sort the mail so they can browse it less painfully. I’m sure that spam ranking is already happening, only the general public isn’t benefiting from it as much as they could.

Create Alternating Background for Search Results

Isn’t this a no brainer? Just a slightly different hue on alternating search results would be so nice to have.

 

Share Wonders

Look out honey, because I’m using Technology