display image file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
display image file
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?
-
- Posts: 101
- Joined: Wed Dec 22, 2010 8:17 pm
Re: display image file
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
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
Re: display image file
Hi mmasson,
So you mean an "image object".
This DOES requre to create an image object! No image object, no image
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
Please check the very useful "templateimage" (and other templateXXX) in the dictionary!
Done
Call it with where- and whenever you need:
...
placeImageOnCurrentCard "/Users/klaus/Desktop/Images Net/banana.png",100,100
...
Best
Klaus
"Simple" is relativemmasson 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?

No, there is of course NOT such a command, but this can be easily scripted, see below.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.
To avoid misunderstandings, please use the correct terminology! image <> field!mmasson wrote:Can this be done without first creating an image field on the card?
So you mean an "image object".
This DOES requre to create an image object! No image object, no image

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

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

Call it with where- and whenever you need:
...
placeImageOnCurrentCard "/Users/klaus/Desktop/Images Net/banana.png",100,100
...
Best
Klaus
Re: display image file
Thanks Steve and Klaus... both responses were very helpful.
MMasson
MMasson