1

I am creating an image like this:

ffmpeg -i chapter_Border.jpg -vf scale=220x176 chapter_Border.jpg -y';

how can I cut 15.5px from the bottom and 15.5px from the top of the image so that the image has a height of 145px.

2 Answers 2

1

Using imagemagick:

Get the size of the image:

identify img.jpg
# img.jpg JPEG 1024x768 1024x768+0+0 8-bit sRGB 29.2KB 0.000u 0:00.000

Crop a part of img.jpg and save it to new.jpg:

convert img.jpg -crop 220x145+0+16 new.jpg
# 220x145 is the new size. +0+16 is the X,Y position (upper left corner)

I don't think that half-pixels are possible.

1

Using ffmpeg,

ffmpeg -i chapter_Border.jpg -vf scale=220x176,crop=iw:145 chapter_Border.jpg -y
4
  • How can I retain the source image dpi and quality? By default it seems to convert to 96 dpi. Jun 21, 2020 at 2:29
  • 1
    Images only have resolution. DPI relates to printing and is just a metadata in image files. Something like exiftool should be able to change it.
    – Gyan
    Jun 21, 2020 at 7:30
  • I ended up using jpegtran which allowed me to crop losslessly and helped retain both the dpi and quality of the image. Jun 21, 2020 at 9:06
  • Encoding quality can be retained in ffmpeg by setting the -q value e.g. -q:v 1
    – Gyan
    Jun 21, 2020 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.