Text and image in the same file?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Text and image in the same file?
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?
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?
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
(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
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.
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.
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)for decodingSo 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
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
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
regards
Bernd