extracting the thumbnail from digital photos?

Alejandro Tejada capellan2000 at gmail.com
Mon Jan 26 18:59:50 EST 2015


Hi,

This script works in LiveCode 7.0.1
under Windows:

(Notice that I am using byte instead of char
as recommended in release notes and,
unlike Ubuntu, I have to set the casesensitive
to true to make it work)

First, download this 8 MB image that contains
two thumbnails (320x240 and 160x120):
(this link should be in a single line)

http://216.18.212.226/PRODS/fuji-x100t/FULLRES/X100ThSLI00100NR2D.JPG

Create a stack and put this script
in a button:

on mouseUp
   local temp
   answer file "Select JPEG image with EXIF thumbnail data"
   put it into temp
   open file temp for binary read
   read from file temp for 100000
   put it into temp1
   close file temp

   put numtobyte(255) & numtobyte(216) into tStart
   -- in Hexadecimal: FFD8 = SOI(Start of jpeg image)
   put numtobyte(255) & numtobyte(217) into tEnd
   -- in Hexadecimal: FFD9 = EOI(End of jpeg image)

   delete byte 1 to 2 of temp1
   -- delete JPEG SOI (Start of jpeg image)
   if byte -2 to -1 of temp1 = tEnd then delete byte -2 to -1 of temp1
   -- delete JPEG EOI(End of jpeg image)

   set the casesensitive to true


repeat until offset(tEnd,temp1) = 0

  -- repeat until offset(tStart,temp1) = 0

   put offset(tStart,temp1) into tThumbstart
   put offset(tEnd,temp1) into tThumbEnd

   put byte tThumbstart to (tThumbEnd + 1) of temp1 into tJPGThumb

   delete byte 1 to (tThumbEnd + 1) of temp1

   if tJPGThumb is not empty
   then
      create img
      set the text of it to tJPGThumb
   else
      answer "No JPEG Thumbnails in this image"
   end if

   end repeat
end mouseUp

Al



More information about the Use-livecode mailing list