Help altering some batch edits to have a Transparency
Posted: 2008-06-29T21:41:18-07:00
Alright my friend has helped me setup 2 seperate dos batch files to use imagemagick to do some conversions for me. Both work great....its setup to work with a black background...which i have and works perfect. However what i'm looking for help with is...altering these so that it's not using black but is transparent...so that they'll have the same look/effect regardless of what my background color is. Is this possible, if so would you mind showing me how?
Heres some examples of what the first script does...and the code that does it...
It takes this....
and makes this for me... (to go below it)
So to my understanding it takes the image...flips it...crops it...then places a black gradient over top of it to make it look like its fading out. But what i'd like it to do is have the same size...but instead of placing a black gradient over top of it....turn the the small cropped image into a gradient itself...taht just went from 100% opacity to 0% opacity over the course of the size of it. That way no matter what background i put it over...it holds its look.
@ECHO OFF
:: SET SOME VARS
SET INPUTFILE=%1
SET TMPPATH=%TEMP%\imagicktemp
SET REFLEX=50
set MIRROR=%INPUTFILE:t.jpg=m.jpg%
:: CREATE TEMPORARY DIR
IF NOT EXIST %TMPPATH% mkdir %TMPPATH%
:: FETCH AND SET IMAGE SIZE
FOR /F %%x IN ('identify -format %%w %INPUTFILE%') DO SET IMGWIDTH=%%x
FOR /F %%x IN ('identify -format %%h %INPUTFILE%') DO SET IMGHEIGHT=%%x
Echo Creating file %MIRROR% from %INPUTFILE% (%IMGWIDTH%x%IMGHEIGHT%)
:: CREATING A GAP BETWEEN IMAGE AND REFLECTION
convert -size %IMGWIDTH%x5 xc:black %TMPPATH%\TAG.JPG
:: START ALL THE REAL IMAGEMAGICK
:: CREATE THE UPSIDE DOWN IMAGE AND CROP IT TO 120 HIGH AND 0 OFFSET
convert %INPUTFILE% -flip -crop %IMGWIDTH%x%REFLEX%+0+0 %TMPPATH%\FLIP.jpg
:: MAKE A GRADIANT (TRANSPARENT TO BLACK) AND ADD THE GRADIANT TO THE IMAGE
convert ( -size %IMGWIDTH%x%REFLEX% gradient:none-black ) %TMPPATH%\FLIP.JPG +swap -gravity south -composite %TMPPATH%\REFLECTION.JPG
:: JOIN THE TWO IMAGES
convert %TMPPATH%\TAG.JPG %TMPPATH%\REFLECTION.JPG -append %MIRROR
This second one takes a cover image, rotates it, and also places a mirror like reflection below it...(with or without a glow effect...depending on which i comment out).
Starts off looking like this...(but a bigger version..this is just a thumbnail of norm size)
and can make it look like either this....
or this
Again...it works perfect at the moment, because i'm using a black background behind them....but i would like to have it use transparencies instead of black so that i can make it work with any background color or image.
Heres the code for this one...
@ECHO OFF
:: FETCH AND SET IMAGE SIZE
FOR /F %%x IN ('identify -format %%w %1') DO SET IMGWIDTH=%%x
FOR /F %%x IN ('identify -format %%h %1') DO SET IMGHEIGHT=%%x
:: SET SOME VARS
SET INPUTFILE=%1
SET REFLEX=50
SET GLOW=30
SET DIFF=35
SET /A SHIFT=160
SET /A AUX01=%IMGHEIGHT%-%DIFF%
SET /A AUX02=%IMGHEIGHT%*2
SET /A AUX03=%IMGWIDTH%+%SHIFT%
SET /A AUX04=((%IMGHEIGHT%-(2*%DIFF%))*2)+%DIFF%
SET /A AUX05=%IMGWIDTH%+%DIFF%
SET /A AUX06=(%IMGHEIGHT%/4)+%IMGHEIGHT%
SET /A AUX07=%IMGHEIGHT%+%GLOW%
SET /A AUX08=%IMGWIDTH%+%GLOW%
SET /A AUX09=%DIFF%+%GLOW%
SET /A AUX10=%SHIFT%+%GLOW%
SET /A AUX11=%AUX01%+%GLOW%
SET /A AUX12=%AUX02%+%GLOW%
SET /A AUX13=%AUX03%+%GLOW%
SET /A AUX14=%AUX04%+%GLOW%
SET /A AUX15=%AUX05%+%GLOW%
SET /A AUX16=%AUX06%+%GLOW%
:: START ALL THE REAL IMAGEMAGICK
:: WITHOUT GLOW EFFECT
::convert %INPUTFILE% -matte +repage -virtual-pixel transparent ( +clone +distort Perspective "0,0,0,0 0,%IMGHEIGHT%,0,%IMGHEIGHT% %IMGWIDTH%,0,%IMGWIDTH%,%DIFF% %IMGWIDTH%,%IMGHEIGHT%,%IMGWIDTH%,%AUX01%" ) ( -size %IMGWIDTH%x%IMGHEIGHT% gradient: -evaluate subtract 75%% -evaluate multiply 2 -flip -clone 0 +swap +matte -compose CopyOpacity -composite +compose +distort Perspective "0,0,%SHIFT%,%AUX02% %IMGWIDTH%,0,%AUX03%,%AUX04% 0,%IMGHEIGHT%,0,%IMGHEIGHT% %IMGWIDTH%,%IMGHEIGHT%,%IMGWIDTH%,%AUX01%" ) -delete 0 -background black -mosaic -crop %AUX05%x%AUX06%+0+0 %INPUTFILE%
::WITH GLOW EFFECT
convert %INPUTFILE% -matte +repage -virtual-pixel transparent ( +clone +distort Perspective "0,0,%GLOW%,%GLOW% 0,%IMGHEIGHT%,%GLOW%,%AUX07% %IMGWIDTH%,0,%IMGWIDTH%,%AUX09% %IMGWIDTH%,%IMGHEIGHT%,%IMGWIDTH%,%AUX11%" ) ( +clone -background blue -shadow %GLOW%x%GLOW%+0+0 -channel A -normalize +channel ) +swap ( -size %IMGWIDTH%x%IMGHEIGHT% gradient: -evaluate subtract 75%% -evaluate multiply 2 -flip -clone 0 +swap +matte -compose CopyOpacity -composite +compose +distort Perspective "0,0,%AUX10%,%AUX12% %IMGWIDTH%,0,%AUX13%,%AUX14% 0,%IMGHEIGHT%,%GLOW%,%AUX07% %IMGWIDTH%,%IMGHEIGHT%,%IMGWIDTH%,%AUX11%" ) -delete 0 -background black -mosaic -crop %AUX05%x%AUX16%+0+0 %INPUTFILE%
I'm brand new to this....as i said my friend help put those together for me...so Thanks for any help you can offer me.
P.S. If it matter heres the batch file that runs it all for me.....but i can use either one of those above 1 file at a time if needed...so they do work independently
CHO OFF
SET POPCORNDIR=E:\popcorn\images
FOR /R %POPCORNDIR% %%x IN (*t.jpg) DO CALL E:\popcorn\images\mirror_index.bat %%x
FOR /R %POPCORNDIR% %%x IN (*f.jpg) DO CALL E:\popcorn\images\mirror_details.bat %%x
Heres some examples of what the first script does...and the code that does it...
It takes this....
and makes this for me... (to go below it)
So to my understanding it takes the image...flips it...crops it...then places a black gradient over top of it to make it look like its fading out. But what i'd like it to do is have the same size...but instead of placing a black gradient over top of it....turn the the small cropped image into a gradient itself...taht just went from 100% opacity to 0% opacity over the course of the size of it. That way no matter what background i put it over...it holds its look.
@ECHO OFF
:: SET SOME VARS
SET INPUTFILE=%1
SET TMPPATH=%TEMP%\imagicktemp
SET REFLEX=50
set MIRROR=%INPUTFILE:t.jpg=m.jpg%
:: CREATE TEMPORARY DIR
IF NOT EXIST %TMPPATH% mkdir %TMPPATH%
:: FETCH AND SET IMAGE SIZE
FOR /F %%x IN ('identify -format %%w %INPUTFILE%') DO SET IMGWIDTH=%%x
FOR /F %%x IN ('identify -format %%h %INPUTFILE%') DO SET IMGHEIGHT=%%x
Echo Creating file %MIRROR% from %INPUTFILE% (%IMGWIDTH%x%IMGHEIGHT%)
:: CREATING A GAP BETWEEN IMAGE AND REFLECTION
convert -size %IMGWIDTH%x5 xc:black %TMPPATH%\TAG.JPG
:: START ALL THE REAL IMAGEMAGICK
:: CREATE THE UPSIDE DOWN IMAGE AND CROP IT TO 120 HIGH AND 0 OFFSET
convert %INPUTFILE% -flip -crop %IMGWIDTH%x%REFLEX%+0+0 %TMPPATH%\FLIP.jpg
:: MAKE A GRADIANT (TRANSPARENT TO BLACK) AND ADD THE GRADIANT TO THE IMAGE
convert ( -size %IMGWIDTH%x%REFLEX% gradient:none-black ) %TMPPATH%\FLIP.JPG +swap -gravity south -composite %TMPPATH%\REFLECTION.JPG
:: JOIN THE TWO IMAGES
convert %TMPPATH%\TAG.JPG %TMPPATH%\REFLECTION.JPG -append %MIRROR
This second one takes a cover image, rotates it, and also places a mirror like reflection below it...(with or without a glow effect...depending on which i comment out).
Starts off looking like this...(but a bigger version..this is just a thumbnail of norm size)
and can make it look like either this....
or this
Again...it works perfect at the moment, because i'm using a black background behind them....but i would like to have it use transparencies instead of black so that i can make it work with any background color or image.
Heres the code for this one...
@ECHO OFF
:: FETCH AND SET IMAGE SIZE
FOR /F %%x IN ('identify -format %%w %1') DO SET IMGWIDTH=%%x
FOR /F %%x IN ('identify -format %%h %1') DO SET IMGHEIGHT=%%x
:: SET SOME VARS
SET INPUTFILE=%1
SET REFLEX=50
SET GLOW=30
SET DIFF=35
SET /A SHIFT=160
SET /A AUX01=%IMGHEIGHT%-%DIFF%
SET /A AUX02=%IMGHEIGHT%*2
SET /A AUX03=%IMGWIDTH%+%SHIFT%
SET /A AUX04=((%IMGHEIGHT%-(2*%DIFF%))*2)+%DIFF%
SET /A AUX05=%IMGWIDTH%+%DIFF%
SET /A AUX06=(%IMGHEIGHT%/4)+%IMGHEIGHT%
SET /A AUX07=%IMGHEIGHT%+%GLOW%
SET /A AUX08=%IMGWIDTH%+%GLOW%
SET /A AUX09=%DIFF%+%GLOW%
SET /A AUX10=%SHIFT%+%GLOW%
SET /A AUX11=%AUX01%+%GLOW%
SET /A AUX12=%AUX02%+%GLOW%
SET /A AUX13=%AUX03%+%GLOW%
SET /A AUX14=%AUX04%+%GLOW%
SET /A AUX15=%AUX05%+%GLOW%
SET /A AUX16=%AUX06%+%GLOW%
:: START ALL THE REAL IMAGEMAGICK
:: WITHOUT GLOW EFFECT
::convert %INPUTFILE% -matte +repage -virtual-pixel transparent ( +clone +distort Perspective "0,0,0,0 0,%IMGHEIGHT%,0,%IMGHEIGHT% %IMGWIDTH%,0,%IMGWIDTH%,%DIFF% %IMGWIDTH%,%IMGHEIGHT%,%IMGWIDTH%,%AUX01%" ) ( -size %IMGWIDTH%x%IMGHEIGHT% gradient: -evaluate subtract 75%% -evaluate multiply 2 -flip -clone 0 +swap +matte -compose CopyOpacity -composite +compose +distort Perspective "0,0,%SHIFT%,%AUX02% %IMGWIDTH%,0,%AUX03%,%AUX04% 0,%IMGHEIGHT%,0,%IMGHEIGHT% %IMGWIDTH%,%IMGHEIGHT%,%IMGWIDTH%,%AUX01%" ) -delete 0 -background black -mosaic -crop %AUX05%x%AUX06%+0+0 %INPUTFILE%
::WITH GLOW EFFECT
convert %INPUTFILE% -matte +repage -virtual-pixel transparent ( +clone +distort Perspective "0,0,%GLOW%,%GLOW% 0,%IMGHEIGHT%,%GLOW%,%AUX07% %IMGWIDTH%,0,%IMGWIDTH%,%AUX09% %IMGWIDTH%,%IMGHEIGHT%,%IMGWIDTH%,%AUX11%" ) ( +clone -background blue -shadow %GLOW%x%GLOW%+0+0 -channel A -normalize +channel ) +swap ( -size %IMGWIDTH%x%IMGHEIGHT% gradient: -evaluate subtract 75%% -evaluate multiply 2 -flip -clone 0 +swap +matte -compose CopyOpacity -composite +compose +distort Perspective "0,0,%AUX10%,%AUX12% %IMGWIDTH%,0,%AUX13%,%AUX14% 0,%IMGHEIGHT%,%GLOW%,%AUX07% %IMGWIDTH%,%IMGHEIGHT%,%IMGWIDTH%,%AUX11%" ) -delete 0 -background black -mosaic -crop %AUX05%x%AUX16%+0+0 %INPUTFILE%
I'm brand new to this....as i said my friend help put those together for me...so Thanks for any help you can offer me.
P.S. If it matter heres the batch file that runs it all for me.....but i can use either one of those above 1 file at a time if needed...so they do work independently
CHO OFF
SET POPCORNDIR=E:\popcorn\images
FOR /R %POPCORNDIR% %%x IN (*t.jpg) DO CALL E:\popcorn\images\mirror_index.bat %%x
FOR /R %POPCORNDIR% %%x IN (*f.jpg) DO CALL E:\popcorn\images\mirror_details.bat %%x