3D Transform width a Cover and a special Hover Effekt

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

3D Transform width a Cover and a special Hover Effekt

Post by franz »

Hello,

i'm a german guy and i'm trying to generate this:
Image out of that:Image

I've made it with Photoshop and have uploaded a Picture of each step i've made:

1:Image
2:Image
3:Image
4:Image
5:Image
(The Size of the Image (500x550) is important)

And now i'm trying to realize it with ImageMagick (Command Line) but i'm failing already on the first step.
I'm deeply grateful for every help!

Franz
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: 3D Transform width a Cover and a special Hover Effekt

Post by fmw42 »

IM has a -distort perspective function that allows you to specify four sets of points (presumably the corners in the source and destination images) and do a perspective warp of the image. You probably want the +distort form or the use of the "-set option:distort:viewport {geometry_string}" to set the size of the viewport. see
http://www.imagemagick.org/script/comma ... hp#distort

Alternately you can try my 3Drotate script that allows you to specify rotation angles. You can get it at http://www.fmwconcepts.com/imagemagick/index.html

Here is an example:

original
http://www.fmwconcepts.com/misc_tests/P ... andril.jpg

first perspective
pan=40

3Drotate pan=40 pef=0.5 idy=64 auto=out mandril.jpg mandril_p40_pef0p5_idy64.jpg

http://www.fmwconcepts.com/misc_tests/P ... _idy64.jpg


second perspective
tilt=-120 and pan=40

3Drotate tilt=-120 pan=40 pef=0.5 idy=64 auto=out mandril.jpg mandril_tm120_p40_pef0p5_idy64.jpg

http://www.fmwconcepts.com/misc_tests/P ... _idy64.jpg

The bottom of the first should match the top of the second.
franz

Re: 3D Transform width a Cover and a special Hover Effekt

Post by franz »

Hello,

i've reached the first step with this code:

Code: Select all

convert 88m.jpg -virtual-pixel white -distort Perspective "0,0 0,0 0,5 0,5 303,0 303,35 303,435 303,400" -resize 250x435! 88m_temp.jpg

convert 88m.jpg  -virtual-pixel white -distort Perspective "0,0 0,0 0,5 0,5 303,0 303,85 303,435 303,350" -resize 237x435! -rotate 207.7 -flop  88m_temp_mirror.jpg
Image
Image

Both Pictures fit together, but how can i get them in one Picture?(500x550)
Before I put both pictures together i've to make a gradient form light to dark in the second picture (the mirrored one). I think with "-fx" i could realize that, but how?

Thank you for helping!

Frank

//Edit: the problem with overlaying them is, that the background isn't transparent and when i use "-virtual-pixel transparent -background transparent" and save this as a .gif everything is displaced and only the second picture is really transparent :? Is it possible to overlay both pictures in one step with generating them (without saving them between both steps) ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: 3D Transform width a Cover and a special Hover Effekt

Post by fmw42 »

You can composite images together using the -geometry ... -compose ... -composite command. You need to create a background image that is transparent first of the final size.

To make a transparent background use:

convert -size WIDTHxHEIGHT xc:none <outputimage>

The -geometry command tells you where to place each image.
The -compose command tells you how to overlay them. You probably want the default which is over or overlay. So you can leave out -compose.
The -composite command does the work.

See

http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/script/comma ... ?#geometry
http://www.imagemagick.org/Usage/canvas/#other

To tell -distort to make a transparent background use:

convert <inputimage> -matte -channel RGBA -virtual-pixel transparent -distort ...

see
http://www.imagemagick.org/Usage/misc/#virtual

With the use of \( ... \) you can probably combine all this in one step.

see
http://www.imagemagick.org/Usage/basics/



You should study and use as reference these two great pages of Anthony Thyssen

http://www.imagemagick.org/Usage/
http://www.imagemagick.org/Usage/reference.html

These links can be found at the main IM site map page:

http://imagemagick.org/script/sitemap.php

P.S.

To make a gradient use:

convert -size WIDTHxHEIGHT gradient:

This will make a gradient in the vertical direction

You can use composite -blend to blend the image with the gradient

You probably want to do the gradient blend before doing the perspective on that image.

see

http://www.imagemagick.org/Usage/canvas/#gradient
http://www.imagemagick.org/Usage/compose/#blend
franz

Re: 3D Transform width a Cover and a special Hover Effekt

Post by franz »

It's working now!!! Jiiha ;D

here the code i've used:

Code: Select all

convert cover.jpg -virtual-pixel transparent -background transparent -distort Perspective "0,0 0,0 0,5 0,5 303,0 303,35 303,435 303,400" -resize 250x435! cover_temp.png
convert cover.jpg  -virtual-pixel transparent -background transparent -distort Perspective "0,0 0,0 0,5 0,5 303,0 303,85 303,435 303,350" -resize 237x435! -rotate 207.7 -flop cover_temp_spiegel.png

composite  -compose Out  cover_temp_spiegel.png  gradient_trans.png  cover_temp_spiegel.png 
convert -size 500x550 xc:black  cover_temp_spiegel.png  -geometry +120+355   -composite  cover_temp.png -geometry +120+30   -composite  cover_cover.jpg
composite -compose Over  -geometry +28+15 hoverlight.png cover_cover.jpg  cover_hover.jpg
(gradient_trans and hoverlight are images which i'Ve made with Photoshop)
Image

Is it possible to shrink the Code and to do it without temporary files?

Frank
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: 3D Transform width a Cover and a special Hover Effekt

Post by magick »

Can you post a URL to your gradient and hoverlight image? You should be able to do the conversion in one command but we need all the images to test the command.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 3D Transform width a Cover and a special Hover Effekt

Post by anthony »

franz wrote: Before I put both pictures together i've to make a gradient form light to dark in the second picture (the mirrored one). I think with "-fx" i could realize that, but how?
I don't think a gradient was present in your original example.
Just a modification to the overall transparency of the image.

That can be done using -evaluate see Im examples
http://imagemagick.org/Usage/transform/#evaluate
which includes just such an example.

Also in a practical way. your mirror-like surface is not right.
A mirror would place the reflection directly in a vertical line between you and the source image. The way you have it the reflection is off to one side making it look artificial.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 3D Transform width a Cover and a special Hover Effekt

Post by anthony »

franz wrote:Is it possible to shrink the Code and to do it without temporary files?
Yes it should be posible.

What I would do is read in the cover image as set
-set option:distort:viewport 500x550+0+0
then make a clone of the cover image and perspective distort directly to the desirded positions on the 'viewport' window. That is the exact coordinates that you want them to appear.
Repeat this for the lower image.

the top image can have a blue 'shadow' added around it.
while the bottom image can be made semi-transparent.

In this way you don't much around with offsets, resizing, flops, rotates, or any other modification you are currently performing. that is all these secondary 'distortions' can be done directly by the perspective distortion operation.

All that you need to do then is overlay the resulting two images together, and that can be done using -flatten onto your desired background color (black in your example)

As such everything can be done in a single command, with a lot fewer operations. However without a good full-size input and output example it is difficult to determine the coordinates to use.

WARNING: I leave for china Thursday week, so if you like me to help create this command I'll need the URL's of the full size example images. You can forum private mail them if you don't want them published.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 3D Transform width a Cover and a special Hover Effekt

Post by anthony »

Thanks for the image...

Using the starting cover image ONLY,
I generated the following single command....

Code: Select all

convert cover.jpg -matte  -crop 307x435+341+0 +repage \
    -virtual-pixel transparent \
    \( +clone  +distort Perspective \
            '0,0 120,30  307,0 370,65  0,435 120,465  307,435 370,430' \) \
    \( +clone -background blue -shadow 100x70+0+0 \
       -channel A -normalize +channel \) +swap \
    \( -size 307x435 gradient: -evaluate subtract 75% -evaluate multiply 2 \
       -flip  -clone 0 +swap +matte -compose CopyOpacity -composite +compose \
       +distort Perspective \
             '0,0 282,900  307,0 470,730  0,435 120,465  307,435 370,430' \) \
    -delete 0 -background black -mosaic -crop 500x550+0+0 \
3d_view.jpg
[/size]
Note that the above is for UNIX/linux. Hoever replace the single quote with double and join up the lines and you can create the equivelent DOS version. See IM examples, API & Scripting, Windows Batch Scripts
http://imagemagick.org/Usage/api/#windows

In summery
The first line of the above extract the front panel of the cover image. The first parenthesis does the initial perspective distortion.

The second parenthesis takes that distortion and generates the blue halo around it with a final swap so that it is behind the perspective view. It is the blur in this operator that takes most of the processing time (70 is a large blur!) It could be replaced by a pre-prepared 'hover' image.

The third parenthesis has two parts. The first part creates a very strong gradient which is used to make the initial cover image (-clone 0) semi-transparent. The second part then perspective distorts that cover using the same coordinates for the bottom edge as the first distort. You can adjust the destination coordinates ( 282,900 and 470,730 ) for the top edge as you like.

After that the original image is deleted and all the images mosaiced together. At this point a final crop trims the overall size of the final image.

Enjoy.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
franz

Re: 3D Transform width a Cover and a special Hover Effekt

Post by franz »

i've translated it for DOS:

Code: Select all

convert cover.jpg -matte  -crop 307x435+341+0 +repage -virtual-pixel transparent +clone  +distort Perspective "0,0 120,30  307,0 370,65  0,435 120,465  307,435 370,430"  +clone -background blue -shadow 100x70+0+0 -channel A -normalize +channel +swap  -size 307x435 gradient: -evaluate subtract 75% -evaluate multiply 2  -flip  -clone 0 +swap +matte -compose CopyOpacity -composite +compose +distort Perspective "0,0 282,900  307,0 470,730  0,435 120,465  307,435 370,430" -delete 0 -background black -mosaic -crop 500x550+0+0 3d_view.jpg
but when i run the script, it says me "missing an image file 3d_view.jpg". The Error is still there if i create manually a "3d_view.jpg" file.

Thank you for making an effort!
Frank
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 3D Transform width a Cover and a special Hover Effekt

Post by anthony »

Where are you parenthesis?

The parenthesis is important as it lets you do a set of image processing on a separate image sequence without requiring a separate command.

See IM Examples, Basics, Parenthesis
http://imagemagick.org/Usage/basics/#parenthesis
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
franz

Re: 3D Transform width a Cover and a special Hover Effekt

Post by franz »

Oh i though that is a kind of "linux command"

These Code even doesn't work:

Code: Select all

convert cover.jpg -matte  -crop 307x435+341+0 +repage \ -virtual-pixel transparent \ \( +clone  +distort Perspective \ "0,0 120,30  307,0 370,65  0,435 120,465  307,435 370,430" \) \ \( +clone -background blue -shadow 100x70+0+0 \ -channel A -normalize +channel \) +swap \  \( -size 307x435 gradient: -evaluate subtract 75% -evaluate multiply 2 \ -flip  -clone 0 +swap +matte -compose CopyOpacity -composite +compose \  +distort Perspective \ "0,0 282,900  307,0 470,730  0,435 120,465  307,435 370,430" \) \ -delete 0 -background black -mosaic -crop 500x550+0+0 \ 3d_view.jpg
Error:

convert: unable to open image `\': No such file or directory.
convert: unable to open image `\(': No such file or directory.
convert: invalid argument for option `\': +distort.


What's wrong with it?

Frank
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: 3D Transform width a Cover and a special Hover Effekt

Post by el_supremo »

The backslashes cause trouble with the DOS command. Try this:

Code: Select all

convert cover.jpg -matte  -crop 307x435+341+0 +repage -virtual-pixel transparent  ( +clone  +distort Perspective  "0,0 120,30  307,0 370,65  0,435 120,465  307,435 370,430" )  ( +clone -background blue -shadow 100x70+0+0  -channel A -normalize +channel ) +swap  ( -size 307x435 gradient: -evaluate subtract 75% -evaluate multiply 2  -flip  -clone 0 +swap +matte -compose CopyOpacity -composite +compose   +distort Perspective  "0,0 282,900  307,0 470,730  0,435 120,465  307,435 370,430" )  -delete 0 -background black -mosaic -crop 500x550+0+0  3d_view.jpg
Pete
franz

Re: 3D Transform width a Cover and a special Hover Effekt

Post by franz »

Now it works perfectly, but the gradiant on the mirrored picture is missing

Image
With my Code it looks like that:
Image


Frank
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 3D Transform width a Cover and a special Hover Effekt

Post by anthony »

The reflection gradient is in the code, and is applied to the image before it is distorted into the reflection. It was working in my origina code. Note certain why it is missing in your result.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply