exporting images in RTF from runrev

Ken Ray kray at sonsothunder.com
Tue Nov 25 21:08:20 EST 2008

Thanks for that, Franz! I've been able to *reference* images on disk with
RTF, but wasn't sure how to *embed* them!

It took your code, abstracted it a bit, and adapted it slightly to accept
optional width, height and format (in case anyone cares if it's JPEG vs PNG)
- watch line wraps:

on mouseUp
  put imageToRTF(long id of img 1,"","","png") into tRawRTF
  ask file "Save RTF as:"
  if it <> "" then
    writeRTFDoc tRawRTF,it
  end if
end mouseUp

on writeRTFDoc pRawRTF,pFileName
  put "{\rtf" & pRawRTF & cr & "}" into tRTF
  if the platform is "MacOS" then set the fileType to "MSWDRTF "
  put tRTF into url ("binfile:" & pFileName)
  put the result into tResult
  if tResult <> "" then return "Error:" && tResult
end writeRTFDoc

function imageToRTF pImageRef,pOpt_Width,pOpt_Height,pOpt_Format
  local tData,tImageBinary,tW,tH
  if exists(pImageRef) then
    if (pOpt_Format="") or (pOpt_Format is not among the items of
"jpeg,png") then put "jpeg" into tFormat
    else put toLower(pOpt_Format) into tFormat
    do "export pImageRef to tData as" && tFormat
    get binaryDecode("H*",tData,tImageBinary)
    if pOpt_Width = "" then put the width of pImageRef into tW
    else put pOpt_Width into tW
    if pOpt_Height = "" then put the height of pImageRef into tH
    else put pOpt_Height into tH
    put (tW * 1440) into tW  -- convert pixels to twips
    put (tH * 1440) into tH  -- convert pixels to twips
    put "{\pict\" & tFormat & "blip\picwgoal" & tW & \
        "\pichgoal" & tH & " " & cr & tImageBinary & cr & \
        "}" into tRetVal
    return tRetVal
    return "Error: Image '" & pImageRef & "' does not exist."
  end if
end imageToRTF

> Some users could not confirm my problems with bigger jpegs in return.

I've encountered this - there's a maximum limit to the size of an image
object in Rev - I've successfully gotten to 4000 x 4000 pixels, but if it's
too large you get an error in attempting to import the image into Rev. Not
sure of the exact maximum though...

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/

More information about the use-livecode mailing list