Is there any picture there?

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
user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Is there any picture there?

Post by user#606 » Sun May 31, 2009 4:39 pm

How do you test if an image contains a picture or not?
all the usual suspects
empty <>= contains "" size either show nothing or 0
I have looked through the dict and user and other examples with images, but found nothing.
Any ideas?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun May 31, 2009 5:14 pm

Hi user....

At some point, you have to set the text, filename, imagedata, maskdata, or whatever. Whenever you do this, you could also set a special property, e.g. cHiIContainAPictureThankYouVeryMuch. Whenever you add a picture, set the cHiIContainAPictureThankYouVeryMuch to a file path or picture name; whenever you delete the imagedata or filename you set the cHiIContainAPictureThankYouVeryMuch to empty again. That way, you will always know whether your image object contains a picture.

You might even write a handler like this:

Code: Select all

setProp cHiIContainAPictureThankYouVeryMuch theFilename
  set the filename of the target to theFileName
  pass cHiIContainAPictureThankYouVeryMuch
end cHiIContainAPictureThankYouVeryMuch
or

Code: Select all

setProp cHiIContainAPictureThankYouVeryMuch theText
  set the text of the target to theText
  lock messages
  set the cHiIContainAPictureThankYouVeryMuch of the target to empty
  unlock messages
end cHiIContainAPictureThankYouVeryMuch
It might also be possible to check the formattedHeight and formattedWidth, but I don't know by heart right now what these properties report if an image object is empty.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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 5:58 pm

you can do:

Code: Select all

put image "yourImageName" = empty
returns true to the message box if image is empty
regards
Bernd

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

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

Thanks Mark, I was wide of the target on this. I have taken Filename as only a "name of a file" not the content of a container.
Anyway, It is so much clearer now.
The issue was to check if the user remembered to add a photo with his text. I wanted to test if pic + text + radio buttons were set before processing, so setting a flag would not help, because the image holder would be there empty or full. All fields, containers and radio buttons are cleared on processing.
Anyway, thank you again.

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

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

Nifty as always, thanks Bernd

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun May 31, 2009 6:06 pm

Hi Bernd,

Your suggestion doesn't work with filenames, but if User consistently uses the text property of image objects, then it should work fine.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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 6:19 pm

thanks Mark for pointing this out,

it is a little tricky how Rev treats images that you either reference by a filename or create by setting the text of an image or by manually painting into them for that matter.
So make that

Code: Select all

put (image "myImageName" = empty) and (the filename of image "myImageName" = "")
That should take care of an empty image and of an image that is referenced through a filename (if only testing for image = empty it would return true if the image is referenced by a filename, and actually not "empty" at all.

regards
Bernd

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 8:09 pm

user#606,

if you want to make thumbnails and you want to use and image object for this, one thing to watch out for is that even if you set the thumbnail to a smaller size than the original image all the information in the thumbnail is that of the original image. That is the filesize is not reduced.
You can see the effect if you set the text of image 2 to the text of image 1. Than you reduce the size of image 2 manually. Create a new card go that card and come back to the card with image 2 on it. If image 2 was not locked in size (in the inspector) it will be of the original proportions of image 1.
To get around it you can do the following:

Code: Select all

set the imageData of image 2 to the imageData of image 2
So effectively setting the imageData of image 2 to its own imageData reduces the image to the thumbnail size with regards to its true (as shown) width and height.

may be you know all this but if you dont it can be puzzling and well you dont get the lower file size you are looking for in the thumbnail.

regards
Bernd

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 10:01 pm

user#606,

more to the point of what I was saying about thumbnails is this script:

Code: Select all

on mouseUp
   -- lets have an image P1 and P2, P2 is supposed to be a thumbnail of P1
   -- assume you have set the lockloc of image p2 to true in the inspector
   -- lockloc is the same as lock size and position in "size and position" of the inspector
   
   -- first we test whether it is a referenced image that has a filename
   put the filename of image "p1" into tfileName
   if tFileName <> "" then -- has a filename
      set the imageData of image "p1" to the imageData of image "p1"
      put the text of image "p1" into tImageText
      set the filename of image "p1" to tfileName
   else  -- has no filename
      put the text of image "p1" into tImageText
   end if
   
   put the width of image "p1" into twidth
   put the height of image "p1" into theight
   put 120 into tNewHeight
   put tNewHeight / theight into tfactor
   
   -- no need to round() for decimals, Rev does it for you in this case
   -- tNewWidth scales the width of the image proportionaly down (or up)
   -- depending on tNewHeight. 
   put twidth * tfactor into tNewWidth
   
   set the text of image "p2" to tImageText
   set the width of image "p2" to tNewWidth
   set the height of image "p2" to tNewHeight
   
   -- until now it is just a resize without really changing the original 
   -- dimensions, they are still there so if you take the image information
   -- you would get an image of the original size
   
   -- take this out after testing
   put "image size after resizing before 'set imageData ... to imageData'" &&  length(text of image "p2") & return
   
   -- this reduces the size of the image to the thumbnail dimensions permanently
   set the imageData of image "p2" to the imageData of image "p2"
   
   -- take this out after testing
   put "image size after resizing – after– 'set imageData ... to imageData'" &&  length(text of image "p2") after msg
   
end mouseUp
if you try this you see what I mean

if you for your thumbnail you go this way you save the snapshot bit (which is a very handy features)
You could also create the thumbnail to a hidden image p2 if you dont want it to be seen.
regards
Bernd

edited to take into account images that are references to files
As Mark pointed out above

Post Reply