Combining to images

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hairydalek
Posts: 57
Joined: Sat Feb 01, 2014 8:57 pm

Combining to images

Post by hairydalek » Sat Feb 01, 2014 9:20 pm

I'm new to LiveCode, but what I'd like to to is turn what I have done for a web page into an application.

Here's what happens:

1 - user uploads an image (a photo, max 3mb in size for the moment)

2 - user then choses an option, and a sticker is added to the image

3 - the server then creates an image with the same resolution as the original, but with the sticker applied in a random place.

So, what I have been trying to look for is for a way two get LiveCode to put image B in a random place on image A. So far, nothing has cropped up that suggests that this can be done in LiveCode, without waking through the image pixel by pixel, copying the pixels into a new image. Somewhere along the way, you have to determine if the pixel to be replaced is from the the original image, or from the sticker image. This strikes me as being very clunky, slow, and complex to write, is there a way of saying something like:

Code: Select all

Position image B on image A at postionX , positionY, angle Xdeg
None of the examples on LiveCode's site even get close to what I would have thought is a simple option. Am I missing something basic?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7257
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Combining to images

Post by jacque » Sun Feb 02, 2014 12:59 am

LiveCode can do it fairly easialy and you won't need to get down to the pixel level. LiveCode provides properties that tell you the dimensions of every object, so in pseudocode:

get the width of the image
get a random number within that range
add the left of the image to the random number. That's the first item of the sticker's location, call it randomH
If the width of the sticker will exceed the right of the image, subtract half the sticker width from randomH

get the height of the image
get a random number within that range
add the top of the image to the random number. That's the second item of the sticker's location, call it randomV
Adjust randomV the same way you did for randomH, if the sticker will exceed the height of the image

set the location of the sticker to randomH,randomV

Now you have a sticker image on top of the orginal. Use the snapshot command to make a new image of the composite.

If you need help with the actual scripting, let us know.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13858
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Combining to images

Post by Klaus » Sun Feb 02, 2014 12:59 am

HI hairydalek,

1. welcome to the forum! :D

2. Quick idea:
Put image B onto a card in the lowest layer
Scale image A to the size you want
Set the angle of image A to the desired degree
Set the loc of image to somewhere on top of image B
-> compute a random location for this from the loc/width/height of image B
Finally: Export a snapshot from the area of image B
DONE! :D

Know what I mean?
Just like you would do it with a piece of paper and scissors 8)


Best

Klaus

hairydalek
Posts: 57
Joined: Sat Feb 01, 2014 8:57 pm

Re: Combining to images

Post by hairydalek » Sun Feb 02, 2014 2:08 pm

HI,
thanks all! After your answers and a little bit of extra digging, I appear to have got the kind of effect I want. :lol:

I’m using junky images at the moment, but my next job will be to create proper images for the stockers, and get the user to choose one (or more) to add.

Actually easier than I expected it to be - though my initial expectation is that things will be a lot harder.

One thing I found I had to do was not to screensnap the image, bur create group of the image and the sticker and screensnap that.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7257
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Combining to images

Post by jacque » Sun Feb 02, 2014 4:58 pm

That's a common problem for folks who come from other languages. Possibly the hardest thing you'll have to do is get used to how much simpler LiveCode is. .:-)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Multimedia”