how i can do this in Imagemagick command line?

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
snoke
Posts: 7
Joined: 2014-10-26T15:44:45-07:00
Authentication code: 6789

how i can do this in Imagemagick command line?

Post by snoke »

Hello

I want do this in Imagemagick command line, but I'm not get...

$img_r = imagecreatefromjpeg($capa);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
imagejpeg($dst_r, $capa);

Thank you for help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how i can do this in Imagemagick command line?

Post by snibgo »

From the desription of imagecopyresampled at http://php.net/manual/en/function.image ... ampled.php , this function is equivalent to a "-crop" and "+repage", followed by "-resize", followed by "-compose Over -composite" with a "-geometry" setting.
snibgo's IM pages: im.snibgo.com
snoke
Posts: 7
Joined: 2014-10-26T15:44:45-07:00
Authentication code: 6789

Re: how i can do this in Imagemagick command line?

Post by snoke »

Sure, but I'm not able to get there.

You can help me? I can send a donation via paypal if you help me.

:)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how i can do this in Imagemagick command line?

Post by Bonzo »

I can not test this at the moment but try:

Code: Select all

convert background.jpg ( input.jpg -crop 500x500+10+10 ) -gravity center -composite output.jpg
You may need to use \( and \) instead of ( and )

You can more options once this is working if required.
Imagemagick command line
Is this using php?

Code: Select all

exec("convert background.jpg ( input.jpg -crop 500x500+10+10 ) -gravity center -composite output.jpg");
You WILL need to use \( and \) instead of ( and ) if on a Linux type machine Windows just uses ( and )
snoke
Posts: 7
Joined: 2014-10-26T15:44:45-07:00
Authentication code: 6789

Re: how i can do this in Imagemagick command line?

Post by snoke »

Thanks, but I still can't get what I want.

Please check the image: http://oi60.tinypic.com/5xk0n7.jpg

I have this jquery script, and I want crop the image using imagemagick.

I can do this with PHP GD using this code:

Code: Select all

$targ_w = 404;
$targ_h = 316;

$file = 'image.jpg';

$img_r = imagecreatefromjpeg($file);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
imagejpeg($dst_r, $file);
But I have difficulty to get the exact command to get this.

Thank you for helping!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how i can do this in Imagemagick command line?

Post by Bonzo »

If you only want a crop:

Code: Select all

exec("convert input.jpg -crop 200x200+10+10 output.jpg");
snoke
Posts: 7
Joined: 2014-10-26T15:44:45-07:00
Authentication code: 6789

Re: how i can do this in Imagemagick command line?

Post by snoke »

I want resize and crop...
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how i can do this in Imagemagick command line?

Post by Bonzo »

Code: Select all

exec("convert input.jpg -resize 300x300 -crop 200x200+10+10 output.jpg");
snoke
Posts: 7
Joined: 2014-10-26T15:44:45-07:00
Authentication code: 6789

Re: how i can do this in Imagemagick command line?

Post by snoke »

Thanks for helping, but it not working:

Code: Select all

Array
(
    [x] => 94
    [y] => 16
    [w] => 409.1139240506329
    [h] => 320
)

exec("convert input.jpg-resize '202x158!' -crop {$_POST['w']}x{$_POST['h']}+{$_POST['x']}+{$_POST['y']} output.jpg");
I want get the first image: http://oi60.tinypic.com/5xk0n7.jpg
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how i can do this in Imagemagick command line?

Post by Bonzo »

Give this a try:

Code: Select all

convert input.jpg -resize 500x500 -crop 409x320+14+16 +repage -gravity center -background white -extent 500x500 -flatten temp.png

convert temp.png ( -size 500x100 xc:white -fill blue -pointsize 16 -gravity northwest -annotate +20+0 "Test" -fill black -pointsize 14 -gravity northwest -annotate +20+40 "Test" ) -append output.jpg
In your code you need a space before -resize and your dimensions are incorrect as your resize is smaller than your crop.
First convert is resizing the original photo then cropping it with an x, y offset. It is then putting it on a 500 square white background.
The second convert is creating an image with a white background, adding the text and joining the two images.

I do not know if the text will be as good a quality as you will want.
snoke
Posts: 7
Joined: 2014-10-26T15:44:45-07:00
Authentication code: 6789

Re: how i can do this in Imagemagick command line?

Post by snoke »

Thanks for helping, but it not working...

Objectively, how I can get do this with Imagemagick?

Code: Select all

$dst_r = ImageCreateTrueColor($targ_w, $targ_h); 
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
ImageCreateTrueColor equal convert input.jpg -resize 500x500 output.jpg ?

imagecopyresampled equal convert input.jpg -crop {$_POST['w']}x{$_POST['h']}+{$_POST['x']}+{$_POST['y']} output.jpg

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

Re: how i can do this in Imagemagick command line?

Post by fmw42 »

Perhaps you should provide an example input and output with your exact command using actual numbers and not arguments. That way some one can actually run a test comparison.

You can upload to any free hosting service such as dropbox.com and put the URLs here.
snoke
Posts: 7
Joined: 2014-10-26T15:44:45-07:00
Authentication code: 6789

Re: how i can do this in Imagemagick command line?

Post by snoke »

Code: Select all

$dst_r = ImageCreateTrueColor(404, 316); 
imagecopyresampled($dst_r, $img_r, 0, 0, 297, 0, 404, 316, 253, 197);

convert input.jpg -resize 404x316 output.jpg 
convert input.jpg -crop 253x197+297+0 output.jpg
http://oi60.tinypic.com/343g215.jpg - result of PHP GD
http://oi61.tinypic.com/fjnr6d.jpg - result of imagemagick

It's not working, and I don't know how i can convert PHP GD code to Imagemagick command line...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how i can do this in Imagemagick command line?

Post by fmw42 »

Where is the input image?

Just a guess without seeing the input but perhaps

Code: Select all

convert input.jpg -resize 404x316 -crop 253x197+297+0 output.jpg
Post Reply