Resize image by length with image magick - imagemagick

I'm trying to resize a image by its length, the width should remain. Is sounds quite easy, but somehow i don't get it. I'm using it together with PHP via the command line.
I'm using ImageMagick 6.7.3-9
By reading the docs, i would do the following:
/usr/local/bin/mogrify -resize x200! myimg.png
That gives me:
mogrify: negative or zero image size `bbb.png' # error/resize.c/ResizeImage/2570.
My goal is, that if bbb.png is w:400 h:400 i can resize it to w:400 h:200.
mogrify -resize x200 //Height with new width
mogrify -resize 200 //Width with new height
mogrify -resize 200! //New Width, old height
Can someone explain me, what I am doing wrong? Thanks

Known broken, now fixed. Fix should be in ImageMagick-6.7.4-0 Beta available 2011-12-08.

I have not found your Image Geometry fromat -resize x200! in documentation. I think you should use
xheight
or
widthxheight!
I.e.: -resize x200 or -resize 400x200!.

Related

ImageMagick: How do I do a simple crop?

All I'm trying to do is crop images to a width of 1400 pixels from the left, but leave them at the same height.
The format should be width: 1400px, height 100% (unchanged), offset X and Y are both zero, so +0+0 (for X and Y):
convert -crop 1400x100%+0+0 inputfile outputfile
This doesn't actually do anything! Can someone help me with my syntax?
Your syntax for ImageMagick is not correct. It may work in ImageMagick 6, which is forgiving, but not in ImageMagick 7. Read the input before any operations.
What you need to do is just specify Wx+0+0, without including H. That will tell ImageMagick, that you just want the width cropped. For example:
Lena:
convert lena.png -crop 100x+0+0 +repage result.png
Include +repage for those formats that support virtual canvas, such as PNG and TIFF. JPG does not need it, but it won't hurt.
See https://imagemagick.org/Usage/crop/#crop_percent
I figured it out. The 100% isn't necessary. It should be:
convert -crop 1400x+0+0 inputfile outputfile

imagemagick: how to get image size after resize?

I'm resizing my image using imagemagick, however, I'm not specifying the exact size:
convert $filename -resize 1080000# -quality 100 $reduced_filename
it's resized within a bound, now the problem is, after resize, the size in the EXIF is no longer correct, and I don't have a clue of calculating the new size (e.g. percentage resize can let me calculate new size based on percentage).
So is there a way to get image size after resizing?
Thanks!
You can use ImageMagick's "convert" command to access the image dimensions with a command like this...
convert $filename -format "%[w]x%[h]" info:
Like this...
First create a start image 1024x768:
convert -size 1024x768 xc:black start.jpg
Now resize, and output new size info in one fell swoop:
convert start.jpg -resize 50% -format "%wx%h" -write info: result.jpg
512x384

Batch crop images to fixed height (CLI)

I have images of variable height and width, and I want to crop them all to be 200 pixels high, without any resizing. i.e. their width will remain the same, and height will be 200px. I want to use "north" gravity for this.
Any CLI tool that allows batch processing would be OK - imagemagick/mogrify, gm, etc. I've tried to figure this out but can't find any option to just leave width unspecified.
mogrify *.png -gravity North -extent x200 -path ./complete
The mogrify utility would suite your batch task with -gravity, -extent, and -path options:
You could leave the width unspecified by, well, leaving the width unspecified, and use extent to do the cropping:
convert in.png -extent x200 out.png
or, say,
mogrify -extent x200 *.png
For the wizard example image, that would turn this into this. You can see more resizing examples on the examples site, as well as some different ways of doing cropping.

Resize image based on memory size

I need to resize image based on memory.
What I am getting is following option in "convert" command.
-resize 800x600
-resize 25%
Is there any command like -
-resize 10KB
Thanks
Use this:
convert input.jpg -define jpeg:extent=300kb ... output.jpg
If you want a way to do something similar with Python, I wrote an answer that works pretty well here. It does a binary search for a JPEG quality that satisfies a maximum size requirement.

Imagemagick: Convert to fixed height, proportional width

Using Imagemagick, I'd like to convert a batch of PNGs to a fixed height of 1080px and a proportional width. With proportional I mean this: If the original Image is scaled down 16.8% to 1080px, the width also needs to be scaled down by 16.8%.
Any way of using convert without having to calculate the exact geometry before (using identify and some bash calculation shenanigans) ?
Try this:
convert -resize x1080 {from_path} {to_path}
Image geometry is an option described to use with -resize
xheight Height given, width automagically selected to preserve aspect ratio.
So you only have to specify the height
There is one additional example. give it some values to the resize parameters and it'll automatically resize your image. Plus you can chose other parameters (gravity center or crop etc.).
convert image_example: \
-resize x160 -resize '160x<' -resize 50% \
-gravity center -crop 80x80+0+0 +repage image_example.jpg
Cheers

Resources