display image file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mmasson
Posts: 3
Joined: Tue Nov 15, 2011 4:03 am

display image file

Post by mmasson » Tue Nov 15, 2011 4:11 am

Is there a simple way to specify in a script an image file that is to be placed into a particular location on a card? If there is such a command, it would have to take the image file path and name and the location on the card as parameters. Can this be done without first creating an image field on the card?

Steve Denney
Posts: 101
Joined: Wed Dec 22, 2010 8:17 pm

Re: display image file

Post by Steve Denney » Tue Nov 15, 2011 5:10 am

Hi mmasson, there's any number of ways to do this.
Have a look at create in the dictionary. Then look at all the image properties--mouseOver displays the property's script reference. You can then generally write a script to set that property. Below is a quick example. Might have bugs & if i were serious I'd have more safeguards (like what if they pick a really big image or choose a loc that won't fit, or a negative non integer?) but anyway... I'm not sure what you're after. Probably I'd make a template, have fields for user entry or enable users to drag the imported image to wherever they wanted. Sky's the limit, really. It's up to you.
Steve

Code: Select all

on mouseUp
   create img newImg
   set the showBorder of img newImg to true -- just to see it easily if no img (default is in centre of card)
   -- now get a file path. You can  filter to only display image files if u so choose
   answer file "Where is your image?"
   if it is empty then
      delete img newImg
      exit mouseUp
   else
      put it into tfilePath
   end if
   set the fileName of img  newImg to tfilePath
   ask info "Where do you want your image to go?" & return & return & "format is x,y" & return & "where x and y are numbers of pixels from the left & top of your card" 
   if it is empty then
      exit mouseUp
   end if
   if "," is not in it then
      exit mouseUp
   end if
   put item 1 of it into x
   put item 2 of it into y
   if (x is not a number) or (y is not a number) then
      exit mouseUp
   end if
   set the loc of img newImg to x,y 
end mouseUp

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: display image file

Post by Klaus » Tue Nov 15, 2011 12:59 pm

Hi mmasson,
mmasson wrote:Is there a simple way to specify in a script an image file that is to be placed into a particular location on a card?
"Simple" is relative :)
mmasson wrote:If there is such a command, it would have to take the image file path and name and the location on the card as parameters.
No, there is of course NOT such a command, but this can be easily scripted, see below.
mmasson wrote:Can this be done without first creating an image field on the card?
To avoid misunderstandings, please use the correct terminology! image <> field!
So you mean an "image object".

This DOES requre to create an image object! No image object, no image 8)

OK, here a handler the accepts three parameters:
1. absolute path to the image field
2. X location on the card
3. Y location on the card
It does not take into account if the image is bigger than the current card, I will leave this up to you :-)
Drop a line if you need help with this, too.

And of course it does not check for errors like WRONG parameters etc.
Since you want to do this by script, I am sure you will provide the correct params 8)

Please check the very useful "templateimage" (and other templateXXX) in the dictionary!

Code: Select all

command placeImageOnCurrentCard tFilePath,tX,tY
  lock screen
  set the filename of the templateimage to tFilePath
  set the loc of the templateimage to tX,tY
  create image
  reset the templateimage
end placeImageOnCurrentCard
Done :D

Call it with where- and whenever you need:
...
placeImageOnCurrentCard "/Users/klaus/Desktop/Images Net/banana.png",100,100
...


Best

Klaus

mmasson
Posts: 3
Joined: Tue Nov 15, 2011 4:03 am

Re: display image file

Post by mmasson » Tue Nov 15, 2011 7:26 pm

Thanks Steve and Klaus... both responses were very helpful.

MMasson

Post Reply