Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript: Reset Height, Width of <img> Tags

AppleScript: Reset Height, Width of <img> Tags
Thread Tools
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Mar 22, 2004, 08:56 AM
 
Does anybody where I could find an AppleScript that does this:

Loops through all the <img> tags in an HTML document and retrieve the current width and height attributes of the image referenced by the tag, and insert those values in the appropriate place.

So say you have this:

<img src="images/my_image.gif" height="32" width ="68">

but the image's real height is 190 and its width is 223, the script would change it to:

<img src="images/my_image.gif" height="190" width ="223">

Thanks.
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 4, 2004, 04:26 PM
 
Hmmm, that might be a useful script. Let's see, what would be the easiest way to grab an image's dimensions? I could probably throw such an AppleScript together if there's an easy way to fetch the image's dimensions.

It would probably be easiest to implement the script as a droplet, so it parses each file you toss on its icon. Of course it would have to handle relative as well as absolute references to the graphic. Relative references would be relative to the HTML file on the local HD, but absolute references would have to look on the net for the file. This may be more of a problem. Although i suppose it could look for an HTML comment tag containing a root directory on the local HD to use for absolute images. Yeah, it could be done (provided there's an easy way to read the image's dimensions).
     
Mac Elite
Join Date: Nov 2003
Location: Rockville, MD
Status: Offline
Reply With Quote
Apr 4, 2004, 11:31 PM
 
Well, I discovered that the latest version of Lasso has a built-in function for fetching all kinds of info about an image (including height and width --- yay!) on the server side, so I went with that. No muss, no fuss -- it works great.

Still, this client side AppleScript we're talking about would help a lot of web designers who want to do all that before uploading the images to a server.

Maybe ImageEvents under Panther would allow this? I'll bet it would.
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Apr 4, 2004, 11:49 PM
 
Originally posted by selowitch:
Well, I discovered that the latest version of Lasso has a built-in function for fetching all kinds of info about an image (including height and width --- yay!) on the server side, so I went with that. No muss, no fuss -- it works great.

Still, this client side AppleScript we're talking about would help a lot of web designers who want to do all that before uploading the images to a server.

Maybe ImageEvents under Panther would allow this? I'll bet it would.
PHP has that too - if you're making pages that will get lots of hits, though, having a server-side script that fetches image size has the potential to give quite a performance hit. I'd do it only if you're unsure of the destination image's size, or it changes frequently (eg. a dynamic folio page)
Computer thez nohhh...
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 4, 2004, 11:53 PM
 
I'm still using Jaguar as my Mac doesn't (officially) support Panther... Haven't gotten around to installing Panther with XPostFacto yet.

I think there's probably a way to read the image size info using Perl, but i'm not completely sure.

And isn't Safari's rendering engine part of the OS? There's probably a way to get at it that way too.

I'm sure there must be a way somehow, without resorting to third party software.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Apr 5, 2004, 04:15 AM
 
ImageEvents can tell you the Dimensions of an Image via AppleScript.
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 5, 2004, 11:38 AM
 
Originally posted by Diggory Laycock:
ImageEvents can tell you the Dimensions of an Image via AppleScript.
But it requires Panther.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:03 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2