Page 2 of 2

Re: revCopyFile - What am I doing wrong?

Posted: Sat Apr 01, 2017 11:05 am
by AxWald
Hi,
Klaus wrote:Nowadays OS X uses file suffixes to determine the filetype and
one or two OS versions later Resource forks on Mac OS will be history!
I remember that, back in the good old days when Macs was still Macs etc., we had much fun poking the Windows people for having to rely on such crude mechanisms like file suffixes ;-)
Maybe the iJail inmates will soon have to learn about the benefits of drive letters, too? ;-)))
rumplestiltskin wrote:[...] check chars 5 to 8 for the presence of "jfif" [...]
Does this seem reasonable?
Caution - for some strange reasons valid JPEGs on my Win machine have the "JFIF" in bytes 7 to 10!
In Hex:
FF D8 FF E0 00 10 4A 46 49 46 00 [...]
In ASCII:
ÿ Ø ÿ à · · J F I F · [...]
(Spaces between Bytes added)

After playing with it a bit, I'd use such code:

Code: Select all

on mouseUp
   answer file "Show me the candidate, plz!"
   if it is empty then exit mouseUp
   put it into myFile 
   open file myFile for read
   read from file myFile for 42 chars
   close file myFile
   if ("ÿØÿà" is in it) AND ("JFIF" is in it) then
      answer "It seems to be a valid JPEG!" titled "Congraz!"
   else
      answer "Oh my god - it's full of chars! " & CR & CR & it titled "Bummer!"
   end if
 end mouseUp
Have fun!

Re: revCopyFile - What am I doing wrong?

Posted: Sun Apr 02, 2017 12:35 am
by rumplestiltskin
Well, I thought I was in the clear but discovered that when jpegs come from places other than my Mac, sh-t happens. JPEGS coming from Lightroom on my PC look like this when dropped into TextEdit:

ˇÿˇ·;ÍExif

Re: revCopyFile - What am I doing wrong?

Posted: Mon Apr 03, 2017 1:32 pm
by MaxV
Hi,
just read the magic number of the file: https://en.wikipedia.org/wiki/File_format#Magic_number and https://en.wikipedia.org/wiki/Magic_num ... ramming%29

So if the first 4 chars of a file are: byteTonum() = 255 216 255 224 , then is a JPEG image.