value

Perl on your Mac part 2

By Jon Gales


If you missed my last lesson read
it before you read this one. If not you have a good change of being lost. If
you don’t feel 100% about last weeks lesson that is ok, you will after today.
The last lesson was a quick into to the basics of Perl, scalar variables and
the print function. We will be covering them both in more detail as well as
standard input and comments.

Scalar variables:

    • Always
    marked with a $ before ($scalar_variable)
    • Can contain A-Z, a-z, 0-9, and underscores in the name and must
    start with a letter.
    • Integers and character strings can be assigned as the value
    • Can be assigned different values in the same script such as:

    $one = 1;
    $one = 2; #$one now contains 2

    • Are
    case sensitive so $A and $a are two different scalars
    • Can be used in conjunction with each other such as:

    $one = 1;
    $two = 2;
    $answer = $one + $two;

    The operators
    for Scalar’s are

    as follows:

    Add

    =
    +
    Subtract

    =
    -
    Divide

    =
    /
    Multiply

    =
    *

    To increment
    a scalar (has to be a number) add ++ or — after it like:

    $value
    = 6;
    $value++; #the ++ increases the 6 to a 7
    print $value; #will print 7

    This is the
    principal that web counters work on. When a visitor visits the page it triggers
    a Perl script that reads a number from a file increases it by one prints it
    to the web and then prints it to file for the next time a hit is occurred.

Print
function:

The
print function is probably one of the most
important things you will need to learn
in Perl. Thankfully it is simple. Perl doesn’t
actually print things (on your printer)
it outputs them on screen. To print something
just put the following:

print
"WHAT YOU WANT TO PRINT";

You
can print scalars, strings, numbers, or
whole files (you will learn this at a later
date). Be careful to quote strings of text
(Perl will let you get away without quoting
scalar variables but not text strings).
Also don’t forget that ending semicolon.

Standard
Input:

We
briefly touched this in our last lesson
but not enough to thoroughly understand
it. The code for standard input looks like
this:

$VARIABLE_NAME
= <STDIN>;
chomp($VARIABLE_NAME);

That
chomp isn’t always needed but is a good
idea because sometimes input can get an
extra line in it and we don’t want that.
If there is nothing to chomp it does nothing.
This code picks up whatever was typed in
and dumps it into the $VARIABLE_NAME variable.

Comments:

Comments
are pieces of text that are solely meant for
human readers of the code. The computer automatically
ignores them. In Perl they are marked by a
pound sign #. Everything after a pound sign
is ignored. You have to comment every line
(there are no multi-line comments in Perl
like there are in C, PHP, and many other languages).
Commenting is a really really really really
(did I make my point?) good idea. Even if
you code looks good after your 5th Mountain
Dew at 3 a.m. I promise you it won’t look
good when your boss is looking over your shoulder
at 9 a.m. The first line of every Perl script
is a comment but this one isn’t ignored, it
tells the comp where to find Perl.


A
simple program using: Scalar Variables, Print
Function and Standard Input and comments is
below:

#!/usr/bin/perl
print "How old are you?
"; #prints
question
$age = <STDIN>; #puts response into
scalar
chomp($age);#get rid of that new line
$age_days = $age * 365; #times age by number
of days in a year
print "You are approximately $age_days
days old
"; #print answer

If
you are in X make the code a text file ending
in .pl and chmod it to 755. Then you can run
it by typing the path to file in the terminal.

 

Homework:
Your homework is to mess with the X
terminal. Practice writing stuff in pico and
chmoding it and moving around the directory.
Here are a few commands to get you started:


ls lists current directory
• cd changes directory (cd usr moves you
to the usr folder, cd / always moves you back
to the root directory).

If
you are on Classic you don’t have any homework
except to get OS X as soon as you can. It is
the future and kicks butt for Perl!

If you are having trouble or would like to ask me a question
please send me mail: jonknee@macmerc.com
or chat through AIM:
jonknee41 (add to buddy list)

Adobe Photoshop Tip– The Frank Miller Sin City Effect

Let me start by admitting that I’m going back to the well on this one, but not so much so that it doesn’t warrant it’s own tutorial. I’ll be using the Adobe Photoshop CS3 Beta for this but you can use anything from Photoshop CS on up.

The effect detailed below attempts to capture the look of the Frank Miller graphic novel series “Sin City” and, to some extent, the film (and soon to be “films”) based on it. The most important element of this project is the photograph; if you start with a bad image, you’ll end up with another bad image at the end of all this. It should probably be something very dark with the subject of the image harshly lit.

I’ll be using these two I bought off of iStockphoto.com. I’m going to show them side-by-side throughout the whole process as one image is much better suited for this effect than the other.

knife01 Adobe Photoshop Tip   The Frank Miller Sin City Effect gun01 Adobe Photoshop Tip   The Frank Miller Sin City Effect

Step 1: Get inky

Start by duplicating your Background layer in the Layers Palette.

Reset your Foreground and Background colors. (Tap the D key on your keyboard)

Go Filter>Sketch>Stamp… Set the Light/Dark Balance to 8 and the Smoothness to 10. (If your image isn’t as dark and contrasty as it should be, you may have to modify the numbers here. I’ve used 10 and 7 on the picture on the right for this reason) Click OK.

knife02 Adobe Photoshop Tip   The Frank Miller Sin City Effectgun02 Adobe Photoshop Tip   The Frank Miller Sin City Effect

Go Filter>Artistic>Cutout and use settings of 2 for the Number of Levels, and Edge Simplicity of 0, and an Edge Fidelity of 1. Click OK .

Go Image>Adjustments>Threshold and punch in a value of 128 (to get rid of any gray areas). Click OK.

Go Filter>Stylize>Diffuse and use “Anisotropic.” Click OK.

Duplicate the Background layer again and bring the new duplicate to the top of the Layers Palette.

Go Filter>Artistic>Poster Edges and use a setting of 10 for Edge Thickness, 3 for Edge Intensity, and 6 for Posterization. Click OK.

Go Image>Adjustments>Threshold and punch in a value of 25. Click OK.

Go Filter>Artistic>Cutout and use settings of 2 for the Number of Levels, and Edge Simplicity of 3, and an Edge Fidelity of 1. Click OK.

Go Image>Adjustments>Threshold and punch in a value of 128. Click OK.

Go Filter>Stylize>Diffuse and use “Anisotropic.” Click OK.

Set this layer’s Blending Mode to Multiply.

knife03 Adobe Photoshop Tip   The Frank Miller Sin City Effectgun03 Adobe Photoshop Tip   The Frank Miller Sin City Effect

Step 2: See Red

Okay, it really doesn’t have to be red–it could be yellow. Let me explain; traditionally, Frank Miller’s Sin City contained images of stark contrast peppered with the occasional splash one signature color. In the books in my collection, he only used red or yellow… but this is your image, do what you want.

Create a new layer on top of the Layers Palette and set its Blending Mode to Multiply.

Using the Brush tool and one vivid color from the Swatches Palette, paint in a little something in your image–something significant.

knife04 Adobe Photoshop Tip   The Frank Miller Sin City Effectgun04 Adobe Photoshop Tip   The Frank Miller Sin City Effect

Step 3: Looks Like Rain

Reset your Foreground and Background colors. (Tap the D key on your keyboard)

Create a new layer on top of all the others an fill it with a color…any color …doesn’t matter …it’ll be gone in a minute.

Set this layer’s Blending Mode to Lighten in the Layers Palette.

Go Filter>Render>Fibers… and enter in a Variance of 10 and and a Strength of 64. Click OK.

Go Image>Adjustments>Threshold and plug in 190. Click OK.

Create a selection with the Rectangular Marquee Tool somewhere in the middle of the fibers. You see, we want some rain but the Fibers filter on its own ends up looking like brushed metal. Select an area that we can blow up to make the rain for the whole image.

knife05 Adobe Photoshop Tip   The Frank Miller Sin City Effectgun05 Adobe Photoshop Tip   The Frank Miller Sin City Effect

Transform (Command-D) the selected area and drag the Transform box corner handles out to the edge of the image. Hit Enter when you’re done.

Go Filter>Artistic>Cutout and use settings of 2 for the Number of Levels, and Edge Simplicity of 8, and an Edge Fidelity of 1. Click OK.

Go Image>Adjustments>Threshold and punch in a value of 128 (to get rid of any gray areas). Click OK.

Go Filter>Stylize>Diffuse and use “Anisotropic.” Click OK.

We’re going to transform the rain again. So choose Edit>Transform>Distort. We want to scale up the rain again (since the Cutout Filter has a nasty habit of making the rain look like it starts and finishes well within the frame of our image), but we want to give it some drama. So, first drag each of the Transform box corner handles out beyond the edge of the image, then pull the lower corner handles well away from each other (somewhat unevenly, I might add) to create dramatic perspective. Hit Enter when you’re done.

knife06 Adobe Photoshop Tip   The Frank Miller Sin City Effect

gun06 Adobe Photoshop Tip   The Frank Miller Sin City Effect

Now, you see how the second image–the one of the guy holding the gun–does not work so well? I mean, it’s okay…but the source image is key here.

I hope you have fun with this effect.

–Rick

ImageWell 3.5 released, free version discontinued

thumb1103 20080402 200041 ImageWell 3.5 released, free version discontinuedImageWell is a highly recommended light-weight image editing application that gives you the ability to resize, crop,watermark, and edit your images and then upload them to the web, save to your computer or share them via email. It allows you annotate your images with text, shapes and lines, quickly and easily and, new in version 3.5, in also allows you to sharpen your images too.

One of the many reasons why ImageWell has been so often recommended over the years is that the developer offered a free version that would have Xtras added to it if you registered for the fee of USD$19.95. Well, it no longer works like that and I can’t blame XtraLean Software for the change–like all shareware you use and enjoy, ImageWell is worth supporting and paying for. It represents a lot of hard work and the time and effort has a value. I hope you agree.

I encourage you to try the trial version and, if you like it, buy ImageWell and support the development of ImageWell 4.

Note: