Posted by & filed under Coding.

Earlier this week I Googled for how to find the dimensions of an image using Java, and most of the solutions were way more complicated than they needed to be. Most of what I came across was code that opened the image and parsed through the binary code to get the dimensions.

Yes, there’s an easier way.

The BufferedImage class has a couple built in methods that will get the dimensions without much trouble at all thanks to the getHeight and getWidth methods.

import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;

public class ImageSize {
	public static void main(String[] args) {

		BufferedImage img = ImageIO.read(new File("filename.jpg"));

		System.out.println("Width = " + img.getWidth());
		System.out.println("Height = " + img.getHeight());

	}
}

Posted by & filed under Coding.

Want to create a random color in Java? With a bit of math, plus Math.random(), it’s pretty easy.

A bit about colors

Colors on the computer are made up of a red, green, blue triplet; typically called RGB. And each of the 3 pieces can be in the range from 0 to 255. Java also allows us to create a color using floats for the values in the range of 0.0 to 1.0, or from 0% to 100% of that color. We’re going to use the floats.

As an example, pure red will have an R value of 1.0, a G value of 0.0, and a B value of 0.0.

So we know what numbers we need, but we want ’em random. Read more »

Posted by & filed under Computers & Internet.

Came across a handy little tip this afternoon.

I’ve only recently put images into my signature in Outlook and noticed that most of the time the images weren’t included in replies. Turns out when someone sends a message in plain text Outlook defaults to replying in plain text.

It’s easy enough to change the format to HTML, but the plain text version of the signature was sticking.

The tip I came across today was that, once you switch the format to HTML, you can just right click on the plain text version of the signature and pick the right one.

Posted by & filed under Coding.

Wish I had found this years ago…

Screenshot of the Test Mail Server program

Screenshot of the Test Mail Server program

Up until about a week ago my normal process for testing PHP code that sends email was to run sendmail through WAMP and send to my email address. I’m thinking about the amount of time I could have saved had I found this plugin when I first started.

The Test Mail Server Tool runs on your computer and listens on port 25 for outgoing emails, just like sendmail would. Difference is that instead of sending the email out it just saves it to a folder on your computer.

So with your PHP sending out mail messages on port 25 Test Mail Server picks it up, dumps the entire message into a mail file, and optionally opens it up for you. On my notebook they’ll open up in Thunderbird and look almost like a standard email. Only flaw I’ve come across is that images don’t show, and Thunderbird doesn’t give the normal option of viewing images. Could be that the images are coming off of localhost though. Haven’t tried it pulling images from anywhere else.

Posted by & filed under WordPress.

Turns out the Insert JavaScript & CSS plugin needed some serious rewriting. And rather than patching together what I had already written, I just started over and what came out was a much better plugin.

It’s moved homes as well. My plugins are going to move back to Reliti.com.

And I don’t plan on taking the old version off the WordPress plugin site, but I also don’t plan to update that version either. Updates will be done to the version at Reliti.

Posted by & filed under Random.

Sometimes there just isn’t time to get to all the cool stuff that comes through Twitter. So I’ve pasted a few below so you can go out and read up.

All US networks are hackable.

Clocks at Grand Central are all set wrong, on purpose.

20 reasons you should date a geek

Python for Kids can help adults learn to teach programming

Posted by & filed under Programming.

Needed to create a list of the web safe colors for another site of mine. Yeah, I know that web safe colors are outdated. But it was still something I wanted on the site.

Typing in 216 hex color codes was not something I wanted to do though.

Looking over a list of the safe colors I noticed that every color was made up of only the hex pairs 00, 33, 66, 99, cc, and ff. Or, in decimal, 0, 51, 102, 153, 204, and 255. That made it pretty easy to loop through and create the RGB values.

function get_websafe() {
    $vals = array(0, 51, 102, 153, 204, 255);
    $colors = array();
    foreach ($vals as $r) {
        foreach ($vals as $g) {
            foreach ($vals as $b) {
                $colors[] = rgbToHex($r, $g, $b);
            }
        }
    }
    return $colors;
}

Also needed the rgbToHex function, but that was something that was already in place. I’ll go ahead and list it below.

function rgbToHex($r, $g, $b) {
	$hex = '';
	$hex .= str_pad(dechex($r), 2, '0', STR_PAD_LEFT);
	$hex .= str_pad(dechex($g), 2, '0', STR_PAD_LEFT);
	$hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
	return $hex; 
}

You can see the results here.

Posted by & filed under WordPress.

Needed a way to display meta field info in a post as part of a site rebuild I’m working on.

The meta shortcode plugin adds a short code to WordPress that will display the contents of a meta field if it exists, and optionally something else if it doesn’t.

Download
You can get the plugin from the WordPress plugin library.

Usage
Use the [ metafield ] shortcode, without the spaces, where you want the info to appear.

The following attributes are available.

  • field – The name of the field to use. This is the only required attribute.
  • before – Text or HTML to display before the meta field. Defaults to nothing for single meta values or <ul> for cases where there are multiple values for a meta field.
  • after – Text or HTML to display after the meta field. Same defaults as before except it closes the list.
  • sorted – If there are multiple values for a meta key, setting this to true will sort them alphabetically. Setting to false or leaving blank will output in the order entered in WordPress. This attribute has no effect if the meta key only has a single value.
  • empty – Displayed when the meta key is empty or not found. Defaults to empty which means nothing will be displayed if the key isn’t found.

Posted by & filed under Coding.

My desktop is running across 3 monitors, and I really think that I can be more productive using all 3. The setup allows me to keep Netbeans open on one monitor, Chrome open on the second to see whether the code that I just typed looks like I want it to, and references on the third.

The problem is that it’s harder for me to get into a working mode with 3. I’ve found myself switching to my notebook more often recently. It just seems easier to concentrate with one little 13.3 inch screen instead of 3.

Not sure what the answer is, or whether there is one. But there is some irony in the fact that I was trying to work on some code and the idea of this post distracted me enough to come here and type it out.