October 13, 2007

How to Make PNGs Transparent in IE Using CSS

Filed under: CSS, Web Design at 7:47 pm — Comments (4)

You’ve just made an awesome PNG image with alpha transparency, it looks great in FireFox, but your excitement receives a swift kick in the butt when you test it out in Internet Explorer. Don’t worry, there’s a very easy way to make IE 5.5+ obey your transparency needs. All the guides out there can be really overwhelming, so I’ll make this as quick and painless as possible so you can get on with your day.

First let’s grab the fix by Angus Turnbull and a blank “spacer.gif” image, you’ll need to right click / save as and upload these files somewhere on your web server:
http://www.metatitan.com/files/iepng.htc
http://www.metatitan.com/images/spacer.gif

Open the iepng.htc file and near the top edit the path to spacer.gif to where you uploaded it on your web server. Now add this into your CSS stylesheet and change #yourclass to the class you’re working with, and the URL to where you uploaded it.

img, #yourclass { behavior: url(http://www.yoursite.com/path/to/iepng.htc); }

Now we can have transparent pngs like so:

<div id=”yourclass”><img src=”mypng.png” width=”100″ height=”50″ /></div>

This can make backgrounds defined in “#yourclass” transparent as well. You can mess around it, and define the behavior in a different way if that works better for your project, it’s quite flexible and easy to work with.

October 12, 2007

How to Use Quick Mask in Photoshop, the Quick Way

Filed under: Photoshop at 3:27 pm — Comments (0)

Quick Mask is a tool in Adobe Photoshop that allows you to easily isolate an area of the layer you’re working on. This translates to being able to take a man out of 1 picture so that you can place him in different picture, among other nifty things. Like most Photoshop tools, there’s 1 way to do it, and then there’s 100 other ways. In this tutorial I’ll be teaching you the method that I use on a regular basis to quickly use the… quick… mask.

Here’s the image we’ll work with.

Quick Mask Tutorial Picture 1

Our goal here will be to extract Construction Man and the paper he’s holding and place him on a new image. Let’s start by firing up Photoshop, opening this image, and switching to Quick Mask Mode. This can be done by pressing “Q” on your keyboard or clicking the following button on your Tools window (Window > Tools if you don’t have this open).

Quick Mask Tutorial Picture 2

Now select the “Paint Bucket Tool”, and fill in your entire picture, it doesn’t matter what color. If you are in quick mask mode, you’ll see a red overlay appear on your picture.

Quick Mask Tutorial Picture 3

Select the “Polygonal Lasso Tool” and its sub-option “Add to Selection” (the depressed options are shown below). Zoom in real close so you have a precise environment to work in, and begin selecting an area of the man’s lag with the P.Lasso tool. Once you have a nice chunk, press your delete key and you’ll see the red overlay disappear and the colors of his pants will appear. The beauty of the lasso tool is you can cut him out piece by piece at your own pace, give it a few tries, it shouldn’t take long to master this tool.

Quick Mask Tutorial Picture 4

Your image should look like the following once you have fully cut out Construction Man using the P.Lasso tool. If you’ve made a mistake, you can choose the brush tool to fill in the red overlay.

Quick Mask Tutorial Picture 5

Now let’s exit Quick Mask Mode (Press “Q” or click the button again). You should now have the entire man selected, press “CTRL+C” and “CTRL+V”, this will paste the extracted Construction Man on a new layer by himself, leaving the original picture intact below it. You can now move Construction Man wherever he pleases, like so:

Quick Mask Tutorial Picture 6

Have fun with it! It’s a really useful tool for any graphic designer.

How to Backup and Restore Large Databases in MySQL

Filed under: MySQL at 6:15 am — Comments (5)

Most who use MySQL have a nifty program called PhpMyAdmin. There is a good chance that if you are a user of that program, you’re here because you tried to backup or restore a large database through the web based interface and failed. This is a common situation, lucky for us there’s a very easy, fast, and reliable way to do this through the command line! If you’re a Linux user who has SSH access, follow the steps below.

Backing up the Database
Fire up SSH and type the following. Replace USER with your MySQL username, DBNAME with the name of the database you want to back up, and /path/to/backupname.sql to where you want the database backup file to be saved (directory must exist).

mysqldump -a -u USER -p DBNAME > /path/to/backupname.sql

You’ll be prompted for your MySQL password. It’ll get to work after you type that in and press enter, it may take a few moments (or longer if your database is really large).

When you’re returned to the command line you now have a backup file where you specified above. This file is a complete copy of the database at the time you ran the command, the second your MySQL table is updated your backup will be out of date. I suggest you take backups at regular intervals depending on your situation (I will write a guide on how to automatically do backups one day).

Restoring Your Database Backup
Follow these 3 commands to restore your database easily.

First we need to drop your current database so there are no conflicts when we’re restoring

mysqladmin -u USER -p drop DBNAME

Now we’ll remake the database, because it doesn’t exist anymore

mysqladmin -u USER -p create DBNAME

And finally, we’ll populate the fresh new database with your backup file.

mysql -u USER -p DBNAME < /path/to/backup.sql

The variables you should change above are pretty straight forward. If you get errors importing your data, it’s most commonly because your max_allowed_packet isn’t set high enough in /etc/my.cnf - if you have root access, you can go in and make that variable higher. If you don’t have root access, seek support from your web host.

How to Tar / Untar From the Command Line

Filed under: Linux at 5:50 am — Comments (4)

A simple guide for those who are as helpless on the Linux command line as I am. When managing websites, you’ll often need to compact, move and extract a large number of files, here’s how to do it on your Linux box.

Initial Steps
First SSH into your web server and move to the directory of the files you wish to tar up, since tarring an absolute path will save the folder structure as well which is bad (ie: /home/yoursite/public_html/backupthis/ will save the folders home -> yoursite -> public_html -> backupthis). You can get to the folder you need to by typing:

cd /path/to/your/stuff

Creating a Tar
Now that we’re at the directory we want to tar, or the sub-directory, you can do one of two commands depending on what you need.

If you want to save every file / folder in your current location into a file called backup.tar.

tar -cvf backup.tar *

If you want to save a tar named backup.tar with the folder “somefolder” and its contents.

tar -cvf backup.tar somefolder/

You can test/view your tars with the following command:

tar -tvf backup.tar

Extracting the Tar
When you need to extract that tar, the following command will be suffice:

tar -xvf backup.tar

How to Protect Your PHP Code With Encryption

Filed under: PHP at 4:42 am — Comments (1)

This was an article I wrote for Web Hosting Talk back in April 2004. I’ve made a few revisions to it and felt it would be worthwhile to share here as well.

This guide is intended for programmers who frequently take on freelance projects, those contracted over the internet by strangers to make a PHP script. Due to the nature of the web, it’s very easy to get scammed in this exchange, and there usually isn’t much you can do about it if it happens. Luckily for you, you’re 1 step ahead of the scammers by reading this guide before you sent them your script (hopefully).

Scenario: You are paid $1,500 to write a PHP script for Joe Montana. Joe pays you, you send him the script, all is well, until Joe reverses the charges, leaves you out in the cold while you just wasted several weeks and he gets a free script. Now you have to stress yourself with tracking him down to press charges, which most of the time never happens. Debating intangibles over the internet is a sticky situation for the seller, aka service provider, aka you. I just read the same story on another forum, which is all too common, and this prompted me to share this with hopes of protecting your time and profit.

Step 1
Open the file that is critical to the script’s operation and won’t require modifications by the client at any point in time. You’ll want to pick a file that if you take it out of the picture, it will cripple the operation of his script.

Step 2
Paste this snippet at the top of the file, before the script’s operations are run.

$lines = file('http://www.example.com/joemontana.txt');
foreach ($lines as $line_num => $line) {
$license = htmlspecialchars($line);
if ($license == "invalid") {
exit("License Invalid - Please contact THECOMPANY");
}
}

Now do the following:
- Create a .txt file, call it something unique, preferably the name of the project/client.
- Upload the .txt file somewhere accessible from the web, preferably on your server where only you can write to it.
- On Line 1 of the code above: Change example.com/joemontana.txt to your website and path to the text file you uploaded.
- On Line 5 of the code above: Change YOURCOMPANY to its respective variable. You can edit this message to say whatever you want.

Now if at any time you have a reason to disable his script, all you need to do is open that text file, and type the word: invalid

After you save that file, his script will not function. This method is safe for your client; if your server is down, the file doesn’t exist, or anything other than the word “invalid” is in the document, it will function properly.

Step 3
Now you’re thinking, “That’s good Matt, but what if the client isn’t an idiot and he goes in and deletes my protection”. This is where encoding comes into play. Pick your favorite one, if you don’t have one in mind, I suggest IonCube. Encrypting a file with them through their Online Encoder costs 50 cents, which is peanuts when you consider the sheer satisfaction you’ll receive if a client does scam you and you’re able to pull the rug from under them.

After your file is encrypted, open it up in a text editor, you should see a bunch of nonsensical data in there. Pack it up and ship it to your client! It’s important to remember that you’re not safe from being scammed, always exercise caution when doing business over the Internet. You’ll at least have a lot more control over the situation using these methods.

I suggest that you inform your client that you will be encrypting the file. Include instructions and offer to install the IonCube loaders on their server. Make sure to tell them to upload the encrypted file in BINARY mode, as it will not work otherwise. You should send them the unencrypted file after a couple months from their payment (or whenever you feel it has fully cleared and you’re safe) for their convenience, people don’t like being under the gun forever.

These instructions are provided without warranty. Any damage or loss, yadda yadda yadda *insert long disclaimer here*, is your own fault.

« Previous Page