File:pictureCellToJPEG.sit.hqxServer:www.orange-road.comModified:7/15/98; 11:04:23 PMSize:3KOwner:khagler@orange-road.com Attachments:http://www.primenet.com/~reynol/script/f4/htmlimage.html
This is a utility script which takes the content of a Filemaker Pro picture cell and converts it to a JPEG file using Clip2GIF. It also returns an HTML string that links to the image file. It was meant to be called by more specialized macros written to put databases on the web. As written, it uses the htmlImage Suite directives to determine where the image goes, but it wouldn't be hard to change this for people who don't use htmlImage.
You can see an example of the JPEG files it produces at http://www.orange-road.com/cels.html
Here is the source code:
on pictureCellToJPEG ( thePICT, charName="", makeThumb = false, alt = "", align = "" ) { «Takes the contents of a picture container cell (passed by FMP) and creates JPEG files. «One full size GIF and one thumbnail will be created, with appropriate HTML code. «This code "borrows" from standardMacros.imageRef, and requires htmlImage. «Mon, Jul 13, 1998 at 8:25:59 PM by KGH local ( folder, url, thumburl, heightwidthstring="", largeFile, smallFile ); «Put the file in a folder as specified by the htmlImage prefs folder = htmlImage.utilities.imageFolder(); if ( typeOf ( thePICT ) != binaryType ) || ( sizeOf ( thePICT ) == 0 ) { « there wasn't any binary data return ( "" )}; « there's no picture, so return an empty string instead of an image tag bundle { « create the full-size file largeFile = html.normalizeName ( charName ) + ".jpg"; « name the full-size file largeFile = folder + largeFile; url = largeFile; url = htmlImage.utilities.RelativePath ( string.replaceAll ( url, ':', '/' ), string.replaceAll( htmlImage.utilities.SiteFolder() + html.data.page.subdirectoryPath, ':', '/' ) ); toys.surefilepath ( largeFile ); with objectModel, clip2gif { « convert the PICT data from the database to a JPEG launch(); save ( thePICT, saveIn: largeFile, as: 'JPEG' )}}; if makeThumb { « only create the thumbnail if it was requested smallFile = html.normalizeName ( charName + "Thumb" ) + ".jpg"; « name the thumbnail version smallFile = folder + smallFile; thumburl = smallfile; thumburl = htmlImage.utilities.RelativePath ( string.replaceAll ( thumburl, ':', '/' ), string.replaceAll( htmlImage.utilities.SiteFolder() + html.data.page.subdirectoryPath, ':', '/' ) ); toys.surefilepath ( smallFile ); with objectModel, clip2gif { « convert the PICT data from the database to a JPEG launch(); save ( thePICT, saveIn: smallFile, as: 'JPEG', maximumSize: {200, 150} )}}; bundle { « create the HTML try { « attempt to get the height and width string if makeThumb { « do the thumbnail size local ( hwlist = pbs.getJpegHeightWidth ( smallfile ) ); heightwidthstring = "height=" + hwlist [1] + " width=" + hwlist [2]} else { « don't want a thumbnail, so do the main image instead local (hwlist = pbs.getJpegHeightWidth ( largefile ) ); heightwidthstring = "height=" + hwlist [1] + " width=" + hwlist [2]}}; local (htmltext = ""); on add (s) { htmltext = htmltext + s}; if makeThumb { « create a link to the large image around the thumbnail add ( "<a href=\"" + url + "\">" ); « this is the link to the main image add ( "<img src=\"" + thumburl + "\" " + heightwidthstring ); if align != "" { add (" align=" + align)}; add (" alt=\"" + alt + "\""); add ("></a>")} else { « no thumbnail needed, just make an IMG tag for the full size version add ("<img src=\"" + url + "\" " + heightwidthstring); if align != "" { add (" align=" + align)}; add (" alt=\"" + alt + "\""); add (">")}; return (htmltext)}}; local ( theRecord = FilemakerLib.getFirstRecord ( "Cel Collection", foundSet: false ) ); dialog.notify ( pictureCellToJPEG ( theRecord [8], makeThumb: true ) )