Mime-Version: |
1.0 |
Sender: |
|
Subject: |
|
From: |
|
Date: |
Tue, 27 May 2003 23:47:07 +1300 |
In-Reply-To: |
<l03130301baf87c743e07@[203.173.227.207]> |
Content-Type: |
text/plain; charset="us-ascii" |
Reply-To: |
|
Parts/Attachments: |
|
|
>I seem to be having difficulties figuring out a way to read a
>JPEG/JFIF file to check if it already has a comment. AS seems quite
>happy to write ASCII character 255, but has difficulty recognizing it
>(i.e. as a delimiter) when reading files. (Yes, I'm betraying my
>computing ignorance.)
There's often more than one way to skin a possum:
set f to choose file of type {"JPEG", "JFIF"} with prompt "choose a
JPEG to which to add a comment"
set o to open for access f with write permission
try
set s to read o from 22
if text item 1 of s = (ASCII character 254) then
set n to ASCII number text item 3 of s
set {c, s} to {text 4 thru (n + 1) of s, text (n + 2) thru -1 of s}
else
set c to ""
end if
if length of c > 0 then
set d to "alter displayed "
else
set d to "insert "
end if
set c to text returned of (display dialog d & "comment?:" default
answer c)
set l to length of c
if l = 0 then
write s to o starting at 22
else
write ((ASCII character 254) & (ASCII character 0) & (ASCII
character (l + 2)) & c & (ASCII character 255) & s) to o starting at
22
end if
close access o
on error
close access o
end try
The above was tested comprehensively... well, OK, more than once,
running OS 7.6.1. I suppose it's not actually fool-proof, as the
first bit of the image (as opposed to the image file) chosen could
perhaps one-day be ASCII character 254? :-o
>Fortunately I'm able to take a break now, for a wine tasting, but
>may return to the task later... or not.
The tasting was alright, but not wonderful. Now it's probably time
to stop talking to myself. I'd still be interested, though, if
anyone has an explanation for the (reproducible) difficulties
encountered earlier re. reading until ASCII character 255.
Noon Ecljpsed
Selected from Ambrose Bierce's "Devil's Dictionary":
EXECUTIVE, n. -- An officer of the Government, whose duty it is to
enforce the wishes of the legislative power until such time as the
judicial department shall be pleased to pronounce them invalid and of
no effect.
|
|
|