convert a picture to a 3D DVD cover

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?".
Morphleus

convert a picture to a 3D DVD cover

Post by Morphleus »

Hi all,

it's been a while I try to find an answer to my problem: make dynamically by my dedicated server a preview like the Imandix software, http://www.imandix.com/.
I have an example:

src image
Image

preview image generetad thanks to Imandix
Image

I read all topics related to that and I can do that

take the different part of my orignal picture

Code: Select all

convert img.jpg  -gravity East -chop 860x0  back.jpg
convert img.jpg  -gravity East -chop 759x0  -gravity West -chop 759x0 spine.jpg
convert img.jpg  -gravity West -chop 841x0  front.jpg
create the good perspective of each part

Code: Select all

convert back.jpg -matte -virtual-pixel transparent -distort Perspective '0,0 60,76   0,1057 60,900   739,1057 626,910   739,0 626,62' back_cover.png
convert spine.jpg -matte -virtual-pixel transparent -distort Perspective '0,0 0,7   0,1057 0,892   81,1057 43,907   81,0 43,0' spine_cover.png
convert front.jpg -matte -virtual-pixel transparent -distort Perspective '0,0 0,0   0,1057 0,907   758,1057 551,859   758,0 551,47' front_cover.png
I try to do that without write a file between each step but no way...
I can't do a merge of all files to have my final picture (for the moment I have a file to do the shadow but I would prefer to do that directly with IM).

Thanks for your help

Edit: my final image must be in png for using transparency.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert a picture to a 3D DVD cover

Post by Bonzo »

Not a great way to do it and you will not have a shadow but I have run out of time tonight to do any more, 3 less tempory images:

Code: Select all

convert input.jpg -write mpr:image +delete ( mpr:image -crop 900x1502+0+0 -matte -virtual-pixel transparent -distort Perspective '0,0 0,50   0,1502 0,1452   900,1502 900,1472   900,0 900,40' -write 480.png ) ( mpr:image -crop 200x1502+1900+0 -write 250.png ) ( mpr:image -crop 900x1502+1100+0 -matte -virtual-pixel transparent -distort Perspective '0,0 0,0   0,1502 0,1502   900,1502 800,1000   900,0 800,150' -write 100.png )

convert -size 1900x1600 xc:none -gravity west 480.png -composite -gravity center 250.png -composite -gravity east 100.png -composite -trim finnished.png 

You will have to modify the co-ordiantes to suite your image but you should get the idea. Also you are going to need some processing power to deal with your images.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert a picture to a 3D DVD cover

Post by fmw42 »

see viewtopic.php?f=1&t=11496&hilit=box

and Anthony's script
Morphleus

Re: convert a picture to a 3D DVD cover

Post by Morphleus »

Thanks for your help.

Sorry Bonzo but I can't use your script, I don't know why but it doesn't work when I test it. Is it possible to get back the error code or something else from IM ??

Now i can do that
Image

my code

Code: Select all

exec ("convert -virtual-pixel transparent 
\( back.jpg -matte +distort Perspective '0,0 60,75   0,1057 60,900   739,1057 625,910   739,0 625,60' \) 
\( spine.jpg -matte +distort Perspective '0,0 625,35  0,1057 625,920  82,1057 680,935    82,0 680,30' \) 
\( front.jpg -matte +distort Perspective '1,0 681,30     1,1057 681,935    758,1057 1230,885   758,0 1230,75' \) -background none -layers merge  +repage  img.png");
I can't understand why but there is no way to stick the spine and the front without a default.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert a picture to a 3D DVD cover

Post by Bonzo »

Try this format to get any errors displayed:

Code: Select all

$array = array();
exec("convert input.jpg output.png 2>&1", $array); 
echo "<pre>".print_r($array)."</pre>";
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert a picture to a 3D DVD cover

Post by anthony »

The -distort can position each of the distorted images in the right place directly (whether it is a negative position or otherwise). Each 'layer' image can then be merged together using -layers merge. Do not add a background until the final step.

This is the basic reason the +distort version exists.

See the basic multiple-distort example...
http://imagemagick.org/Usage/distorts/#box3d
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Morphleus

Re: convert a picture to a 3D DVD cover

Post by Morphleus »

If I use the -distort I have something like that
Image

By using the +distort I'm near the perfect result, but, like your example, http://www.imagemagick.org/Usage/distorts/#box3d, between the spine and front there is a little default.

How can I make a perfect collage between spine and front ??
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert a picture to a 3D DVD cover

Post by anthony »

What do you mean by a little default. If the control points match the image results should match, and it looks fine to me.

The only problem I can see is that distort is currently a little 'blurry' but I have that on my list to fix during the current round of additions for distort.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Morphleus

Re: convert a picture to a 3D DVD cover

Post by Morphleus »

The result
Image

a zoom to the "little default" I'm speaking
Image
there is a little vertical blank line. It's a very little detail but...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert a picture to a 3D DVD cover

Post by anthony »

When selecting the image to look at the original on 'ImageShack' I can see the line you are talking about. It looks like the images did not quite join up right.

I am not certain of why this is happening. It may be the 'fuzzyness' of the current resampling filter that is being used (which is on my todo list for the current round of additions) Try distorting using a setting of
-filter point -interpolate cubic
or even the default 'bilinear' interpolation setting. This turns of the area resampling and goes back to a simple single point interpolated 'lookup' for each pixel color.

OR it could be because the images are being stitched together using a 'over' composition. Try using -compose add before the -layers merge.

Please report your results, good or bad. This is a new aspect of IM, and one that will become very important as more people use it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jhfry

Re: convert a picture to a 3D DVD cover

Post by jhfry »

Leave it alone... the line actually helps... In fact I would suggest you try and make it a bit more obvious. To me the line helps to make it look more like the corner of the spine. Add some shadows, darken the spine part of the image a bit, and it might just begin to look like a photo of the DVD case.
Morphleus

Re: convert a picture to a 3D DVD cover

Post by Morphleus »

When I had your command, it gives me something like that

Code: Select all

exec ("convert layout.jpg -virtual-pixel transparent \( back.jpg -matte +distort Perspective '0,0 62,79   0,1057 62,899   739,1057 625,910   739,0 625,63' \) \( spine.jpg -matte +distort Perspective '0,0 625,37  0,1057 625,920  81,1057 680,935    81,0 680,31' \) \( front.jpg -matte +distort Perspective '0,0 680,31     0,1057 680,935    758,1057 1229,884   758,0 1229,77' \) -compose add -layers merge +repage img.png");
Image

I added a background with shadow
Now I have 2 files,
one for generating shadow under the cover
Image
and another for generating lights
Image

Do you advise me to use that files or directly use IM command to generate light and shadow as I want ??
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert a picture to a 3D DVD cover

Post by anthony »

If the shadows and highlights don't change then using a pre-prepared template is better.

Actually you can combine BOTH shadows and highlights into the same overlay (with a perfect grey background) and add it to the image using -compose overlay or -compose highlight. Which one depends on the order of the images, otherwise they are really the same function.

However I would be interested in how you generated the highlighting images. IT would be a great technique to know.

WARNING: use -compose plus not add (my bad). The former is a proper addition with normal bounds clipping, while the latter is a 'modulus' addition, which can wrap around on the cliiping bounds, turning white to black. See IM Examples Alpha Composition for these two composition methods.

I noticed you have added soft shadow to lift the image off the page.

Do you plan to add a 'floor mirror' as well?

I have been looking for way to add surface blur and texture to mirrored images but have not had a lot of luck with this as yet (not that I am looking hard, as I have lots of other things to do too).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Morphleus

Re: convert a picture to a 3D DVD cover

Post by Morphleus »

I did what I wanted:

Image

I used a grey layer to do lights and shadows, it works perfectly.

But I have another issue, my background is always blank and not transparent, I forgot something ??

Code: Select all

exec ("convert layoutwm3.png -virtual-pixel transparent \( back.jpg -matte +distort Perspective '0,0 62,79   0,1057 62,899   739,1057 625,910   739,0 625,63' \) \( spine.jpg -matte +distort Perspective '0,0 625,37  0,1057 625,920  81,1057 680,935    81,0 680,31' \) \( front.jpg -matte +distort Perspective '0,0 680,31     0,1057 680,935    758,1057 1229,884   758,0 1229,77' \) -layers merge +repage img.png");
exec ("composite img.png  layer.jpg -compose Overlay img.png");
P.S. I don't need to use a floor mirror, sorry :(
jhfry

Re: convert a picture to a 3D DVD cover

Post by jhfry »

Looks great... pretty damn impressive that you could pull that off with only two commands. What adds the black border?
Post Reply