Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
User Journal

Journal Journal: Applescript to make thumbnails and javascript image swaps

I've added to and expanded the Diane Kirkland website (http://dianekirklandphoto.com/)...she's really done some nice images. So, in order to make all this work, I had to learn some javascript that most people would find routine...and then, because I made thumbnails by hand for two of the pages, I got tired of that and cobbled together this applescript (a lot of chunks from Apple's site):

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}
set thehtml to ""
set thehtml2 to ""
 
tell application "Finder"
    activate
    try
        set the source_folder to choose folder with prompt "Pick a folder containing the images to process:"
        set these_files to every file of the source_folder whose file type is in the type_list or name extension is in the extension_list
        repeat with i from 1 to the count of these_files
            set this_path to (item i of these_files) as string
            tell application "Image Events"
                set this_image to open file this_path
                set theWidth to 100
                copy dimensions of this_image to {currentWidth, currentHeight}
                if currentWidth is greater than currentHeight then
                    -- image is wider than high so scale width
                    scale this_image to size theWidth
                else
                    -- image is taller than wide so scale height
                    set the theHeight to (currentHeight * theWidth) / currentWidth
                    scale this_image to size theHeight
                end if
                set new_name to my change_name(alias (this_path))
                set the new_image to save this_image as JPEG in file new_name of the source_folder
                set thehtml to thehtml & "img[" & (i - 1) & "] = new Image(); img[" & (i - 1) & "].src = " & quote & name of source_folder & "/" & the name of this_image & quote & ";" & return
                set thehtml2 to thehtml2 & "<a href=\"javascript:imageSwap(" & (i - 1) & ")\"><img class=\"imagethumb\" src=\"" & name of source_folder & "/" & new_name & "\" ></a>" & return
                close this_image
            end tell
        end repeat
        set the clipboard to thehtml & return & return & thehtml2
    on error error_message
        display dialog error_message buttons {"OK"} default button 1
    end try
end tell
 
on change_name(this_file)
    set this_info to the info for this_file
    set this_name to the name of this_info
    set this_extension to the name extension of this_info
    if this_extension is missing value then
        set the default_name to this_name
    else
        set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
    end if
    return (the default_name & "_th." & the this_extension)
end change_name

And what's really nice about this for me is that I got it to put on the clipboard after making the thumbnails the chunks of the HTML/javascript I needed:

<script type="text/javascript">
var img = new Array();
img[0] = new Image(); img[0].src = "bw/Blueridge-17.jpg";
img[1] = new Image(); img[1].src = "bw/Blueridge-23.jpg";
img[2] = new Image(); img[2].src = "bw/Blueridge-31.jpg";
img[3] = new Image(); img[3].src = "bw/Coast-25.jpg";
img[4] = new Image(); img[4].src = "bw/Coast-34.jpg";
img[5] = new Image(); img[5].src = "bw/Piedmont-19.jpg";
img[6] = new Image(); img[6].src = "bw/Plains-27.jpg";
 
function imageSwap(x)
{
 
var imageObj = document.getElementById("imgbig");
imageObj.setAttribute("src", img[x].src);
 
}
</script>
 
<a href="javascript:imageSwap(0)"><img class="imagethumb" src="bw/Blueridge-17_th.jpg" ></a>
<a href="javascript:imageSwap(1)"><img class="imagethumb" src="bw/Blueridge-23_th.jpg" ></a>
<a href="javascript:imageSwap(2)"><img class="imagethumb" src="bw/Blueridge-31_th.jpg" ></a>
<a href="javascript:imageSwap(3)"><img class="imagethumb" src="bw/Coast-25_th.jpg" ></a>
<a href="javascript:imageSwap(4)"><img class="imagethumb" src="bw/Coast-34_th.jpg" ></a>
<a href="javascript:imageSwap(5)"><img class="imagethumb" src="bw/Piedmont-19_th.jpg" ></a>
<a href="javascript:imageSwap(6)"><img class="imagethumb" src="bw/Plains-27_th.jpg" ></a>

...so that I didn't have to cut and paste and increment a zillion times. Heh!

User Journal

Journal Journal: RSS and SQLite from the command line.

So there's all this RSS being downloaded and managed in the background in a SQLite database...and my email is being managed much the same way...so why not use command line SQL calls to manipulate the syndication feeds?

sqlite3 ~/Library/Syndication/Database3 "select * FROM Articles WHERE source_id = 80;" | bbedit

Y'know, like that.

User Journal

Journal Journal: Into February, tagged and commented.

Another week of fairly serious dabbling in technologies and languages...making RSS and HTML get all parsed and objectified and available for databases and learning how Python can pretty much be wrapped up all pretty in a Mac OS X application.

I've really got to spend some time writing the rest of what is the content of my company site...explaining what the heck it is that I do, explaining why I'm the one to do it, just...explaining.

User Journal

Journal Journal: Awash in technologies, brain swimming.

One of my new year's resolutions...not really stated out loud as such, is to take all of these new things I've learned about lately, like Objective-C and Cocoa and RSS and XML and Python and shell scripting and javascript and put them together in some arguably useful ways to create cool stuff for making graphics on television easy and good looking. Yes..that is what I will do! (I tell myself.)
The Internet

Journal Journal: Movable type-ized.

So I threw the big switch and this morning Positively Atlanta Georgia went online powered by the Movable Type cgi/perl thingie engine product dude item.

This is a good thing, I s'pect, although it'll be a good while before I've done enough to get the other stuff that this site contains converted over and it becomes more of a routine event to post a new entry.

I've spent a lot of time messing with the CSS styles for this and Nancy's site, reading and re-reading the stuff about designing to web standards, and generally getting up to speed. this is about the third or fourth attempt to impose a content management system on this site, which has at various times been powered by Frontier and a great big cumbersome GoLive thing that really didn't make any sense--what was I thinking?

Actually, I've been thinking 'what was I thinking' a lot lately--since I'm a guy who has to look up the format for simple URL links, this slogging of tableless code, a festival of interlocked divs, is enough to make me reach for some serious iced coffee.

The Internet

Journal Journal: A CSS layout epiphany!

Well, I got inspired by Dave Shea's Zen Garden pages sufficiently to sit down with GoLive and see what could be done to yank my site out of the morass of tables and cumbersome type tags so I too could breathe the fresh air of Cascading Style Sheet Layout.

Well, this is easier beheld than done.

I could see what was happening there between all the div tags and the css, but getting my own stuff into those containers was, to say the least, just not happening in GoLive 6...I kept getting things not updating correctly and GoLive's 'helpful' formatting that seemed to try and turn all my objects into 'floating boxes.'

I didn't want floating boxes...I wanted the semantic web, so I switched to a workflow of messing in BBEdit (amazingly, it still doesn't suck) and watching the pages in Safari, which was both satisfying and, I'm sure, somewhat less than realistic.

But boy, once you have one clean page to work with, the satisfaction that comes from tiny css tweaks (and knowing that what you've changed is affecting every page referenced) is huge, and, well, It barely feels like I was up until three am last night dinking around with it.

I proudly showed the results this morning (over the phone) to my brother, who then grumbled about the tables on his site.

This CSS Layout stuff is contagious.

Wireless Networking

Journal Journal: Direcway + Windows 98 + 802.11 = !

Good thing there was lots of beer and wine available.

Although mostly, I drank root beer.

We went down saturday to a house built in the high country near Pine Mountain, Georgia because our friends had installed Direcway two-way satellite "high-speed" internet...and the way it comes in is to one PC, via a USB connector...and these folks have two machines in their home office plus a laptop. They ran Windows 98.

So, after much web-perusing, I determined that if they have Windows 98 Second Edition (whatever that is), they should be able to share and do NAT (Network address translation) through a built-in Microsoft utility called Internet Connection Sharing (an apt name).

And from what I could determine, it's a pain to configure.

Did I mention I'm a Mac person?

So I ran out to an Office Depot in Atlanta and picked up a cheap 10/100 Ethernet card (one of the machines had none), a cheap Speedstream Wireless-plus-switch, and a cheap 802.11 PC Card for their laptop...and 25 feet of Cat 5, and we set off for South o'here.

Got there around mid-afternoon, discovered to our relief that indeed they had Windows 98 Second Edition (and hey, the laptop had Windows 2000) and I spent, well, several hours fighting with the systems....installing ICS, installing networking in general, and configuring the wireless/switch (which really worked perfectly right out of the box.)

Through it all, my beat up Titanium Powerbook was an invaluable testing tool (it recognized the wireless 2 seconds after it was powered up) and reference library (I had downloaded several PDFs and FAQs from such fine sources as the dslreports.com Satellite FAQ.

Number one timewaster and pain in the butt? You had to reboot Windows 98 after any and I mean any change you made in the networking config stuff. Agggghh!

Apple

Journal Journal: Podland (things are better now)

After almost an entire month beating my head against the wall, my peace of mind was restored by the presence of a small Airborne box tucked against our front door.

I had (following instructions) sent my ipod with cracked LCD in to Apple's repair center.

And then waited. And then called. And was told that this repair wasn't Apple's fault...so it will cost about $255 to repair.

Then they told me that they wouldn't repair it at any price, and will be sending it back unrepaired.

And then I heard nothing again for a long time. There were reports that the damaged ipod was sent to Atlanta only to be mis- or un-delivered by Airborne--and was thus returned to Sacramento again.

After more than a month, the box appeared. Nice new ipod inside, wrapped safely in its 'don't steal music' wrapper.

My blood pressure evaporated in a spring breeze.

Apple

Journal Journal: Podland 1

Well, I had to have SOME way of hearing stuff out of my iPod while driving, so I bought a AVWF1 doohickey--something that transmits on the FM band--on one of two fixed frequencies--while driving. And then, of course, Griffin announces--but doesn't ship until march--a much cooler one, about the size of an AA battery which mounts on top of the ipod and uses its power. Damn! I'll have to order one of those, too. And maybe go through the painful return process for the first one.

Slashdot Top Deals

Work is the crab grass in the lawn of life. -- Schulz

Working...