Text and image in the same file?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
822163
Posts: 3
Joined: Thu Feb 26, 2009 4:08 pm

Text and image in the same file?

Post by 822163 » Sat May 30, 2009 10:16 pm

I have a need to save 10 lines of normal text followed by an image.

A photo is placed in a fixed size area on a card with a text field alongside, some how those image pixels become the image data saved after the text.
The purpose of this is to have a single file per record and the image becomes a fixed size, low resolution one.
has anyone done this and how?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun May 31, 2009 12:37 am

Hi 822163,

(I am glad you are not pi :) )

why would you want to do it. It is possible but you create your own file format, that only you could read. Do you want that?
What about the low resolution image? What size do you display the images and what size should the images be saved in?
As far as I see it would be easier to save 2 files that are appropriately named and then reload them, one text, one image file.
May be I dont understand very well what you have in mind.
regards
Bernd

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Post by WaltBrown » Sun May 31, 2009 12:48 am

Looks like "export snapshot from <object> to file "myFile.jpg" as JPEG" might do the trick.

Walt

PS - if you don't want to be able to access the text afterwards, this captures the image and the text as a snapshot.
Walt Brown
Omnis traductor traditor

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Sun May 31, 2009 8:55 am

Thank you bn, the issue is storage space and upload/download time (I failed to make this point, sorry!), so it might be better with two files, one being a thumbnail, the other text.

Waltbrown has given me another option in his PS and if compressed, may be the best answer. You are right, I do not need to edit the text, a point I had failed to consider.

Thank you both, it just shows how useful these discussions can be.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun May 31, 2009 1:24 pm

user#606,

although I would not put the text and the image information into one file as explained above I could not resist to give it a try.

for encoding: (heavily commented)

Code: Select all

-- assuming you have an image named "p2"
-- that you want to store and a text field named "f1"

on mouseUp
   -- put the text field into a variable
   put field "f1" into tf1
   
   -- determine the number of chars of the text
   put length(tf1) into tlong
   
   -- prepare for the amount of text to store in the header
   put length(tLong) into t5DigitsMax
   
   -- no more than 5 digits = 99999 chars
   if t5DigitsMax > 5 then 
      answer "the text has more then 99999 chars, too long" & return & "exit"
      exit mouseUp
   end if
   
   -- the header will hold information about lenght of the text part
   put "" into tHeader
   
   -- if text is less then 5 digits long pad it with leading zeros
   repeat with i = 1 to 5-t5DigitsMax
      put 0 after tHeader
   end repeat
   -- put the actual length of the text part after the leading zeros
   put tLong after tHeader
   
   -- header has the form 00235 for a text that is 235 chars long
   -- we put the header before the text part
   put tHeader before tf1
   
   -- now we append the image information i.e. the whole image as Rev sees it
   put the text of image "p2" after tf1
   
   -- all this data in one variable is stored in a custom properity of the stack for later access
   -- you could store this into a binary file, that is important
   -- because the image information is binary data.
   -- like: put tf1 into URL "binfile:/Main/project/myFile"
   -- since the text is in a binfile it is not cross platform anymore because
   -- Rev does the line platform specific line ending transformation only for text files
   -- cross platform you would have to do it yourself
   set the uTextAndImage of this stack to tf1
end mouseUp
for decoding

Code: Select all

-- assuming you have an image named "p2"
-- that you want to store and a text field named "f1"
-- and the data is stored in a custom property "uTextAndImage"
on mouseUp
   -- get the data from the custom property
   -- or a file you created before
   put the uTextAndImage of this stack into tData
   
   -- check if there is any data to work on
   if tData = "" then
      answer "the data is empty, it has to be filled before extracting" & return & "exit"
      exit mouseUp
   end if
   
   -- get the header information
   put char 1 to 5 of tData into tTextPartlength
   
   -- extract the text part which is the length of the text
   -- take the 5 chars for header information into account
   put char 6 to (tTextPartlength+5) of tData  into tmyText
   
   -- just delete the header and text part from the data 
   -- which leaves just the image information
   delete char 1 to tTextPartlength + 5 of tData
   
   put tmyText into field "f1"
   set the text of image "p2" to tData
end mouseUp
So it is not hard to do, I still would argue against going this way unless you are familiar with Rev and have good reasons to do it. It makes the code harder to maintain etc.
regards
Bernd

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Sun May 31, 2009 6:02 pm

I am indebted to you bn for this.
There is code there that helps me in other respects as well.

Post Reply