Page 1 of 1
how i can do this in Imagemagick command line?
Posted: 2014-10-26T15:54:07-07:00
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.
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-26T20:17:52-07:00
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.
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T05:09:43-07:00
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.

Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T06:15:26-07:00
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 )
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T07:08:40-07:00
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!
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T08:34:42-07:00
by Bonzo
If you only want a crop:
Code: Select all
exec("convert input.jpg -crop 200x200+10+10 output.jpg");
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T08:42:24-07:00
by snoke
I want resize and crop...
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T08:43:22-07:00
by Bonzo
Code: Select all
exec("convert input.jpg -resize 300x300 -crop 200x200+10+10 output.jpg");
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T09:02:27-07:00
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
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T10:04:31-07:00
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.
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T15:28:40-07:00
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
?
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T17:45:05-07:00
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.
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T18:09:48-07:00
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...
Re: how i can do this in Imagemagick command line?
Posted: 2014-10-27T19:14:05-07:00
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