ffmpeg resize large image and high resolution - image-processing

I tried to resize a very big image (457 MB and 21600x21600) with the following command
-i test.png -vf scale=320:-1 out.png
but it throws exception saying "Picture size 21600x21600 is invalid". How can I find out the biggest supported resolution by ffmpeg? Is there a way to resize this high resolution image with ffmpeg?

If you want to use ImageMagick it is included in most Linux distros and is available for macOS and Windows.
Your command becomes:
convert test.png -resize 320x result.png
If you are running v7 or newer, use:
magick test.png -resize 320x result.png
If you have lots to do, and you want all the resized images written in a directory called thumbs you can use:
mkdir thumbs
magick mogrify -path thumbs -resize 320x *.png
Alternatively, you may find vips is a lighter-weight installation and does a faster conversion using less memory:
mkdir thumbs
vipsthumbnail -s 320 -o "thumbs/%s.png" image.png

Related

Thumbnail image from DNG file is inappropriate using imagemagick or exif tool

I have a DNG image and a cropped monochromatic version of the image. Both are generating the same file as the thumbnail when I run any of the below commands:
magick.exe C:\sample1crop.dng -resize 500x375 C:\crop-T.JPG
or
magick.exe dng:C:\sample1crop.dng -intent relative -sample 500x375> -strip -auto-orient -density 72 C:\crop-T.JPG
or
magick.exe convert dng:C:\sample1original.dng -thumbnail 500x375 -filter -auto-orient -density 72 C:\orig-T.JPG
As I am not allowed to upload the DNG files, thus I uploaded the images in hightail, sharing the link below: https://spaces.hightail.com/space/ThDEDYZVey
The generated thumbnail for both the cases:
I tried to get the thumbnail with exiftool as well:
exiftool -b -PreviewImage C:\86854\SLS\Issues\ART-73712\crop-T.JPG > C:\86854\SLS\Issues\ART-73712\thumbnail.jpg
exiftool -b -ThumbnailImage C:\86854\SLS\Issues\ART-73712\crop-T.JPG > C:\86854\SLS\Issues\ART-73712\thumbnail.jpg
but the resulting file seems corrupted. When I extract the exiftool metadata I see:
"ThumbnailTIFF": "(Binary data 42194 bytes, use -b option to extract)"
My requirement here is to get a generic cmd that provides a cropped monochromatic thumbnail similar to the original image.
Using this exiftool command, I was able to extract four images from those files.
You don't mention what OS or shell you're using but if you're using Windows PowerShell, it is known to corrupt binary data when piping or redirecting. Use CMD and you should be able to extract the images properly.

How to set offset when cropping images in imagemagick

My situation is the following:
I have about 7k images (they are all the same resolution)
that I need to crop with an offset of 2px x 2px y how can I archive this?
I already figured out how to run the command for every image in the directory.
I have also tried running
convert image.jpg -crop 97x97 cropped.jpg
It has no offset and it spits out several images instead of just the first cropped one.
You should find this works:
convert INPUT.JPG -crop 97x97+2+2 RESULT.JPG
If so, make a copy of a few files in a spare directory and try with:
cd spare
mogrify -crop 97x97+2+2 *.jpg
Or, if you want them done faster, use GNU Parallel:
cd spare
parallel mogrify -crop 97x97+2+2 {} ::: *.jpg

Animation is lost after converting png to webp

I have an animated PNG image but after I convert it to webP - I get the static image without animation.
I've tried cwebp
$ cwebp -q 100 1.png -o 1.webp
$ cwebp -version
1.0.0
and the same with imagemagick
$ magick 1.png -quality 100 -define webp:lossless=true 1.webp
$ magick --version
Version: ImageMagick 7.0.10-29 Q16 x64 2020-09-05 http://www.imagemagick.org
How can I convert to save the animation?
As discovered, cwebp does not support conversion with animation. Possible solution is to extract the individual frames (using ffmpeg or imagemagick for instance) and use img2webp to generate the animation.

Resize indexed PNG image with ImageMagick while preserving color map

I am using custom batch script to make resized copies (33% and 66%) of all PNG images in folder. Here is my code:
for f in $(find /myFolder -name '*.png');
do
sudo cp -a $f "${f/%.png/-3x.png}";
sudo convert $f -resize 66.67% "${f/%.png/-2x.png}";
sudo convert $f -resize 33.33% $f;
done
It works fine, except when the original image is indexed. In this case the smaller version of the image is RGB (so even larger file size then original image).
I have try several versions but not worked. One that I guess supposed to sort this out was fallowing:
for f in $(find /myFolder -name '*.png');
do
sudo cp -a $f "${f/%.png/-3x.png}";
sudo convert $f -define png:preserve-colormap -resize 66.67% "${f/%.png/-2x.png}";
sudo convert $f -define png:preserve-colormap -resize 33.33% $f;
done
But it doesn't work.
EDIT:
This is updated co, but it still doesn't work as it supposed to (see the attached image-left is original, right is resized):
for f in $(find /myFolder -name '*.png');
do
sudo cp -a $f "${f/%.png/-3x.png}";
numberOfColors=`identify -format "%k" $f`
convert "$f" \
\( +clone -resize 66.67% -colors $numberOfColors -write "${f/%.png/-2x.png}" +delete \) \
-resize 33.33% -colors $numberOfColors "$f"
done
Original image:
Scaled version:
Use "-sample" instead of "-resize" to preserve the color set. This causes the resizing to be done by nearest-neighbor color selection rather than any kind of interpolation.
Otherwise, the colormap ends up with more than 256 colors and the png encoder can't preserve it, due to the 256-color limit on the size of a PNG PLTE chunk. I cannot guarantee that you'll like the appearance of the result, though.
Also, be sure you are using a recent version of ImageMagick.
I'm not observing this problem with the current release (6.9.3-7). Your script works fine and produces clean -2x and -3x images.
There are several things to address here...
find vs glob
You say you want to process all files in a folder, then you use find which will search down into sub-directories as well. If you just want to process files in the current directory, you can let bash do the globbing directly for you. So, instead of
for f in $(find . -name "*.png"); do
you can just do:
shopt -s nullglob
for f in *.png; do
Performance
You run convert twice and load the original image twice, and that is not very efficient. You can run a single process that loads a single image and resizes to two different sizes and writes both to disk. So, instead of
for ...; do
convert ...
convert ...
done
you can write the following to start one convert, read the image once, clone it in memory and write it out, delete the spare copy in memory and then resize the original image and re-save that.
for ...; do
convert "$f" \
\( +clone -resize 66.67% -write "${f/%.png/-2x.png}" +delete \) \
-resize 33.33% "$f"
done
Palette
It seems you actually only want to output palettised (indexed) images with "any" colormap rather than with a "specific" colormap. Glenn's answer is perfect if you want to retain a specific colormap. However, if any colormap is ok, you can use -colors to reduce the colours in the resulting image to a level where the PNG library can make the decision to create a palettised image. Glenn knows a lot more than me about that as he wrote it! However, I think if you reduce the colours to 250 (or so) you will probably get a 256 entry colormap and if you reduce the colours to around 60 or so, you will get a 64 entry colourmap. So, you would do:
shopt -s nullglob
for f in *.png; do
sudo cp ... ...
convert "$f" \
\( +clone -resize 66.67% -colors 250 -write "${f/%.png/-2x.png}" +delete \) \
-resize 33.33% -colors 250 "$f"
done
You can try experimenting with other numbers of colours and see how that affects filesize - the number you need will depend on your images.

ImageMagick fails on php but works in shell

I've this command:
/usr/local/bin/convert -density 200 /singlePage.pdf -colorspace RGB -verbose -geometry 1155 -quality 10 -limit area 100mb singlePicture.jpg
When executing with php (via browser) it has no result output (executing with php function exec()).
When executing the same command on shell, it works perfectly.
I tried another pdf file, which works on php and shell. The only difference is the filesize.
1,0806 MB => Works
1,0962 MB => Not Works
Any ideas?
So this:
/usr/local/bin/convert -density 200 /singlePage.pdf -colorspace RGB -verbose -geometry 1155 -quality 10 -limit area 100mb singlePicture.jpg
implies that the singlePage.pdf file is located on the root of your filesystem. I doubt that is true. My guess is the "/singlePage.pdf" path is wrong.

Resources