compositing 2 images on a website in php

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
scphoto
Posts: 3
Joined: 2016-07-30T09:38:19-07:00
Authentication code: 1151

compositing 2 images on a website in php

Post by scphoto »

I am using imagemagick version: php5-imagick 3.1.0~rc1-1+b2 for my website and version 6.8.1-Q16 on my local machine.

I am a yearbook photographer. Currently my website looks like this:

http://www.scphoto.ca/view-proofs/?ticket_code=PTD4P5M6

I would like to click on one of the backgrounds and display each of the portraits with chosen background.
Alternatively, I could click on one portrait and display that pose with each background but that seems computationaly intensive considering that I'll have several hundred people looking at the page at any given time and one or two a minute in the middle of the night 3 am or 4 am.

What I have already done:
On my local machine I'm using [composite transparent.png bkgrnd.jpg outputfile.jpg] and it works perfectly, I can even add paths to the files. I've been looking for tutorials, but most seem to be installing imagemagick to php or this is what imagemagick does type stuff.

What I need to do:
Figure out how to execute [composite transparent.png bkgrnd.jpg outputfile.jpg] via php on my website.

Questions
Do I have to temporarily save the output files on the server or do they just get sent to the web browser?
Do I need an imagemagick tutorial or a php tutorial?
What don't I know that I don't know? (what should I be googling to teach myself?)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compositing 2 images on a website in php

Post by fmw42 »

For basic imagemagick (not Imagick), see

http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/script/comma ... ptions.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/Usage/compose/#compose

I would recommend you use the the convert .... -composite syntax rather than composite, since you can combine other command with convert and not with composite.

If you want to use Imagemagick in PHP, you would use the exec() command to contain some imagemagick command. User Bonzo has a web site that does most things in PHP exec(). See http://www.rubblewebs.co.uk/index.php

If you want to use Imagick in PHP, then see http://us3.php.net/manual/en/book.imagick.php and use this forum for questions -- viewforum.php?f=18

I do not do much with PHP, but for output images, you need to generate in PHP an HTML image structure to send to the User's for output. See Bonzo's web site, for example.

You need to learn both Imagemagick (or (Imagick) and PHP.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: compositing 2 images on a website in php

Post by Bonzo »

Sometimes a bit of lateral thinking might offer alternative methods:
1/ Work with thumbnail not full sized images for the previews
2/ Generate the photos on either all or the most popular backgrounds before the parents get access - server space is relatively cheap.
3/ Use CSS instead - have a div to hold the image in a div containing the background ( could be a problem with different browsers or devices but I would have though the quickest method ).

Save the parents choice into a database and create the photo at a quite time or on your local PC

Questions
Do I have to temporarily save the output files on the server or do they just get sent to the web browser? - either
Do I need an imagemagick tutorial or a php tutorial? - As fmw42 said use convert instead of composite and if using Imagemagick with php it is a matter of putting your command within exec(" "); and changing your hardcoded paths to variables. Imagick is slightly more complicated but once the code is written it's done. You could run some code to compare the speed of Imagemagick and Imagick I have some speed information here with another link on to a more detailed test.
What don't I know that I don't know? (what should I be googling to teach myself?) - again as fmw42 said check out my site for some ideas.
Last edited by Bonzo on 2016-07-31T04:29:49-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: compositing 2 images on a website in php

Post by Bonzo »

Do not forget your form input validation as well. Even though the user has to log in some people like to screw up others websites.

Imagick is supposed to be a bit more secure than Imagemagick with exec but you still need to validate the data properly.
scphoto
Posts: 3
Joined: 2016-07-30T09:38:19-07:00
Authentication code: 1151

Re: compositing 2 images on a website in php

Post by scphoto »

I want to thank you for responding to my post. You have idea how much I appreciate it. I'm currently reading through you links before I ask anymore questions.

-Gary
scphoto
Posts: 3
Joined: 2016-07-30T09:38:19-07:00
Authentication code: 1151

Re: compositing 2 images on a website in php

Post by scphoto »

Thanks for taking the time to respond to my question. I am really grateful for your response.

1.I am working with thumbnails already 300 x 400 I think. If you saw those pictures of my kid via the link on my website, that's the actual size.
2.Generating the photos beforehand could be done, I'm working with a little over 20,000 images over the course of 2 months and right now I have 20 backgrounds, although you are correct, it isn't expensive for me to move up a webhosting plan to get more space.

3. You are suggesting displaying a png over the jpg backgrounds? With over 10000 students, I'm likely dealing with every type of device out there, and it just has to work with everyone.



-Gary

Bonzo wrote:Sometimes a bit of lateral thinking might offer alternative methods:
1/ Work with thumbnail not full sized images for the previews
2/ Generate the photos on either all or the most popular backgrounds before the parents get access - server space is relatively cheap.
3/ Use CSS instead - have a div to hold the image in a div containing the background ( could be a problem with different browsers or devices but I would have though the quickest method ).

Save the parents choice into a database and create the photo at a quite time or on your local PC

Questions
Do I have to temporarily save the output files on the server or do they just get sent to the web browser? - either
Do I need an imagemagick tutorial or a php tutorial? - As fmw42 said use convert instead of composite and if using Imagemagick with php it is a matter of putting your command within exec(" "); and changing your hardcoded paths to variables. Imagick is slightly more complicated but once the code is written it's done. You could run some code to compare the speed of Imagemagick and Imagick I have some speed information here with another link on to a more detailed test.
What don't I know that I don't know? (what should I be googling to teach myself?) - again as fmw42 said check out my site for some ideas.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: compositing 2 images on a website in php

Post by Bonzo »

As I say I think 3/ would be the fastest but could be problematic.

Just thought I would mention working with thumbnails in case you were using larger images.

A few years ago I worked with a company that were putting custom labels on bottle images. The images needed to be distorted to fit the shape of the bottle. I can not remember the exact amount of label images now but I created about 30,000 final images in one evening. Again they decided using the space was better than creating the images on demand.
I suppose you should do a test and see how long it takes. As I said you must have some backgrounds that are more popular than others which would cut the quantity down. When displaying the image you could check if it exists and create it on the fly if it did not.

Anyway just my thoughts but you can create them on the fly if you prefer to do it that way.

Edit: Thinking about it I generated the images over night not just in the evening.
Post Reply