Page 1 of 2

IM to mimic photoshop styles?

Posted: 2013-11-21T10:20:35-07:00
by crc863
Hello,

Please excuse my ignorance. I'm very new to all of this. I'm trying to manipulate an image via IM to do the following after a user uploads an image with a transparent background.

In photoshop this is how I get my desired effect.

I'll start with this image.
Image

Next I will change the image to transparent and apply the following filters to it.
Image

My end result is this.
Image

Is there any way I can at least get a similar effect to happen with ImageMagick?

Re: IM to mimic photoshop styles?

Posted: 2013-11-21T10:44:19-07:00
by snibgo
Something similar would be possible. For example, see viewtopic.php?f=1&t=23904

Re: IM to mimic photoshop styles?

Posted: 2013-11-21T12:30:16-07:00
by fmw42
In order to do this, I used one of my unix shell scripts, bevel, to do the inner bevel. (The commands for the inner bevel are listed at the bottom of my script example page.)



Here are the commands I used to try to recreate your result. You can tweak the values (adjust gray70 to make the horse figure lighter of darker)

# fordg.png is the input image with gray70 replacing the red
# fordam.png is alpha channel dilated & blurred (to add the shadow) and converted to dithered monochrome to make the noise outside region
# the bevel script adds the bevel to the image converted to gray
# the last command combines the beveled and shadow/noise image and then makes white transparent
# you will need to delete the intermediate images

Code: Select all

convert ford.png \
	\( -clone 0 -fuzz 99% -fill gray70 -opaque red -write fordg.png \) \
	\( -clone 0 -alpha extract -morphology dilate octagon:2 \
		-blur 0x3 -level 0x50% -monochrome -negate -write fordam.png \) \
	null:
bevel -a 225 -w 6 -e 45 fordg.png fordgb.png
convert fordam.png fordgb.png -background white -flatten -compose over \
	-transparent white -write show: ford_result.png
Image

Re: IM to mimic photoshop styles?

Posted: 2013-11-21T15:25:34-07:00
by crc863
Wow that is amazing! Thank you so much! I'm so intrigued by imagemagick. I have lots to learn but think it's going to be pretty fun!

Re: IM to mimic photoshop styles?

Posted: 2013-11-21T15:55:27-07:00
by crc863
I guess I have a couple more questions.

1.) Does the original image need to be a solid color? what if have a multi colored image?
2.) Is there a way to make the end result 25% transparent?

Re: IM to mimic photoshop styles?

Posted: 2013-11-21T16:14:23-07:00
by fmw42
crc863 wrote:I guess I have a couple more questions.

1.) Does the original image need to be a solid color? what if have a multi colored image?
2.) Is there a way to make the end result 25% transparent?
1) no, you can use any image that has transparency. so in the following, I did not convert the original to grayscale.
2) yes, see following example that decreases the transparency channel by a factor of 0.25

Code: Select all

convert ford.png -alpha extract -morphology dilate octagon:2 \
	-blur 0x3 -level 0x50% -monochrome -negate fordam.png
bevel -a 225 -w 6 -e 45 ford.png fordb.png
convert fordam.png fordb.png -background white -flatten -compose over \
-transparent white \
-channel a -evaluate multiply 0.25 +channel ford_result2.png
Image

Re: IM to mimic photoshop styles?

Posted: 2013-11-21T16:16:36-07:00
by crc863
I tried running this on my server.

Code: Select all

<?php
exec('convert images/ford.png \
\( -clone 0 -fuzz 99% -fill gray70 -opaque red -write images/fordg.png \) \
\( -clone 0 -alpha extract -morphology dilate octagon:2 \
-blur 0x3 -level 0x50% -monochrome -negate -write images/fordam.png \) \
null:
freds/bevel -a 225 -w 6 -e 45 images/fordg.png images/fordgb.png
convert images/fordam.png images/fordgb.png -background white -flatten -compose over \
-transparent white -write show: images/ford_result.png 2>&1', $r);
print_r($r);
?>
I received the following errors. I'm thinking it may be a problem with -alpha?

Code: Select all


Array
(
    [0] => 
    [1] => --- FILE images/fordg.png DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---
    [2] => 
    [3] => convert: unable to open image `images/fordam.png': No such file or directory.
    [4] => convert: unable to open file `images/fordam.png'.
    [5] => convert: unable to open image `images/fordgb.png': No such file or directory.
    [6] => convert: unable to open file `images/fordgb.png'.
    [7] => convert: missing an image filename `images/ford_result.png'.
)

Re: IM to mimic photoshop styles?

Posted: 2013-11-21T16:29:33-07:00
by fmw42
It is not finding the images where you think they are. Try putting the script and all the images in the same directory. Be sure you modify the script to set dir="/tmp" and make sure you call it properly if it is bevel.sh or remove the .sh. Also make sure it is executable. See all the steps outlined on my home page regarding Pointers For Use.

Most importantly. You cannot mix scripts in the same a set if convert commands in PHP. Actually you cannot even call two convert commands int the same exec call, as far as I know. So you need to make 3 exec calls to separate the script from the command before and the command after. Also you may need to put the full path to the script.

Re: IM to mimic photoshop styles?

Posted: 2013-11-21T16:45:26-07:00
by crc863
Thank you so much again! I will play with it a lot tonight and try to get it figured out without bugging you too much on the forum =0) You've been incredibly helpful and I appreciate it!

Re: IM to mimic photoshop styles?

Posted: 2013-11-22T12:39:05-07:00
by crc863
I think I was unclear about converting colors. What I meant was that if someone uploads an image, and lets say it's a rainbow gradient on the horse, but i don't know the colors. Is there a way to still convert that horse to all grey?

Also I can't get this working via php exec, I'm going to say it's because I have no clue on how to set up the command lines. Could you show me how to split them up like you said? If I need to reimburse you for your time please let me know. I'm lost =/ Thank you again!

Re: IM to mimic photoshop styles?

Posted: 2013-11-22T13:21:10-07:00
by fmw42
crc863 wrote:I think I was unclear about converting colors. What I meant was that if someone uploads an image, and lets say it's a rainbow gradient on the horse, but i don't know the colors. Is there a way to still convert that horse to all grey?
Do you want the horse and rainbow converted to gray? If so, then my first command set does that, just like it converted the red horse to gray.

Please clarify.
crc863 wrote: Also I can't get this working via php exec, I'm going to say it's because I have no clue on how to set up the command lines. Could you show me how to split them up like you said? If I need to reimburse you for your time please let me know. I'm lost =/ Thank you again!
I am no expert on PHP, but post your code so I can look at what you did? Then I will try to fix it or rewrite the code. But it is best if you try to have all the images and script in the same directory. Once you get that working, you can try to use different directories.

Re: IM to mimic photoshop styles?

Posted: 2013-11-22T13:47:39-07:00
by crc863
This is the first command I'm trying to get working.

Code: Select all

exec('convert images/ford.png
(-clone 0 -fuzz 99% -fill gray70 -opaque red -write images/fordg.png)
(-clone 0 -alpha extract -morphology dilate octagon:2 -blur 0x3 -level 0x50% -monochrome -negate -write images/fordam.png) 2>&1', $r);
The output I get is the instructions for imagemagick.

Re: IM to mimic photoshop styles?

Posted: 2013-11-22T13:56:07-07:00
by crc863
Looks like the convert command isn't listed and I'm only running version 6.2.8 I'm going to guess I have to update? I installed it only a couple of days ago using "pecl install imagick"

Re: IM to mimic photoshop styles?

Posted: 2013-11-22T14:03:13-07:00
by fmw42
You must escape parenthesis and there must be spaces on either side. Also you must have line breaks. Also you need the null: at the end to remove all temp files

try

exec('convert images/ford.png \
\( -clone 0 -fuzz 99% -fill gray70 -opaque red -write images/fordg.png \) \
\( -clone 0 -alpha extract -morphology dilate octagon:2 -blur 0x3 -level 0x50% -monochrome -negate -write images/fordam.png \) \
null: 2>&1', $r);

If this does not work, then you can break this into two commands and an exec for each.

Let me know what happens. It may also be that you need to provide the full path to convert depending upon how PHP is set up.

Yes, 6.2.8 is too old to know about -morphology and many other commands. It is nearly 600 versions old.

to check try

<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>

Re: IM to mimic photoshop styles?

Posted: 2013-11-22T15:23:41-07:00
by crc863
I've updated to the latest version and your command worked!

I added two more commands as you said

Code: Select all

exec('fullpath/freds/bevel -a 225 -w 6 -e 45 fordg.png fordgb.png 2>&1', $b);
exec('convert fordam.png fordgb.png -background white -flatten -compose over \
-transparent white -write show: ford_result.png 2>&1', $c);
print_r($b);
print_r($c);
This DOES generate the image but throws these errors. Do these not matter?

Code: Select all

Array
(
    [0] => <fullpath>/freds/bevel: line 188: bc: command not found
    [1] => <fullpath>/freds/bevel: line 189: bc: command not found
    [2] => <fullpath>/freds/bevel: line 190: [: too many arguments
    [3] => <fullpath>/freds/bevel: line 178: bc: command not found
    [4] => <fullpath>/freds/bevel: line 179: [: -eq: unary operator expected
    [5] => <fullpath>/xgen/freds/bevel: line 199: bc: command not found
    [6] => <fullpath>/xgen/freds/bevel: line 200: bc: command not found
    [7] => <fullpath>/freds/bevel: line 201: [: too many arguments
)
Array
(
    [0] => display: unable to open X server `' @ error/display.c/DisplayImageCommand/426.
)