Imagemagick cropping thumbnail command line - imagemagick

I have an adult website and I want to remove watermarks by Imagemagick commands.
I would like to show you the thing I want as visuals.
Original image comes with 278x140 (I can change these) > Here
What I want is something like this > This
In the default settings of ImageMagick in my website script, that command line is default;
-modulate 110,102,100 -sharpen 1x1 -enhance
and I added next to it -gravity center -crop wxh+0+0 (I filled width and height in the code) but didn't work.
I just want my imagemagick command to crop a smaller square from the middle.
This is my settings in the admin script of the website.
After that, this is my screen of thumbnails in editing content
When I click "regenarate", it doesn't give error, it says success;
But nothing changes in the editing content screen after that. Still same thumbnails.

Using Imagemagick 6.9.9.40 Q16 Mac OSX, I ran your command replacing 1x1 with 0x1 and it works just fine. I took your command from your code JPGs.
Input:
mogrify -modulate 110,102,100 -sharpen 0x1 -enhance -gravity center -crop 150x100+0+0 +repage OX5XX.jpg
I am not sure why you are using mogrify, if you are convert only one image at a time in your loop. You could just use convert as
convert OX5XX.jpg -modulate 110,102,100 -sharpen 0x1 -enhance -gravity center -crop 150x100+0+0 +repage OX5XX.jpg
I would suggest you make a simple PHP command to just run the same as above and see if that works. If it does, then the problem is in your other code and perhaps your usage of FFMPEG. If it does not work, then it could be a bug in your version of Imagemagick.
You can find out the version of Imagemagick by
<?php
exec("convert -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
If that fails, then find the full path to convert via
<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>

Without a complete command it's hard to say exactly where the error might be, but with ImageMagick the first thing I'd try is the same command using "-extent wxh" instead of "-crop wxh+0+0" for this.

Related

ImageMagick v7 conversion of 8bpp images

On Windows 10, I need to crop and resize whole folders of images.
Following the documentation and some answers here i've built this batch:
magick mogrify -path ./cropped -crop 1300x1940+85+130 +repage -resize "800x800^" *.jpg
It mostly works, but when a folder has mixed image formats (some are 24bpp, some are 8bpp, grayscale) this batch skips all the 8bpp ones.
How can i change my command so it accepts and modify every image, no matter what?
Note: i used mogrify as i understand it is needed to process a whole folder and save the result in another one, but i'm unsure it is necessary.

How can I merge or convert multiple ImageMagick command into one single command

a) I have multiple ImageMagick commands and I need to convert those multiple commands into one. I tried it by putting all the parameters in single command, but somehow it was not working and I had to discard it.
magick -density 300 cheque25.jpg -depth 8 -strip -background white -alpha off cheque25.png
magick convert cheque25.png -resize 150% res_cheque25.png
magick convert -brightness-contrast 10x30 res_cheque25.png b_res_cheque25.png
magick convert b_res_cheque25.png -threshold 45% bin_res_cheque25.png
b) Also, is there any chance that merged commands will give any different output than multiple single command?
Your ImageMagick syntax is not correct in several ways. In ImageMagick 7, you replace convert with magick. Also your input should come right after magick. ImageMagick 6 is forgiving of syntax, but ImageMagick 7 is not. See http://imagemagick.org/script/porting.php#cli
Try the following:
magick cheque25.jpg -depth 8 -strip -alpha off -background white -resize 150% -brightness-contrast 10x30 -threshold 45% -density 300 bin_res_cheque25.png
If that does not work, then provide a link to your input image, so others can test your commands and verify against mine.
The combined commands should give the same as a properly formatted set of commands, provided no syntax errors are present and settings are reset where needed and parenthesis processing is properly used when and where needed. I make no guarantees, since your set of commands is not using proper syntax.

ImageMagick: get biggest square out of image

I do have thousands of images in different sizes; now I would like to get the biggest square out of it that's possible without transparent/black background. Of course, the ratio should be kept, if it's e.g. a landscape image all height should be in the destination image but the left and right should be cropped; for portrait images, the other way round.
How's that possible?
I think you mean this. If you start with a landscape image bean.jpg:
magick bean.jpg -gravity center -extent "%[fx:h<w?h:w]x%[fx:h<w?h:w]" result.jpg
If you start with a portrait image, scooby.jpg:
magick scooby.jpg -gravity center -extent "%[fx:h<w?h:w]x%[fx:h<w?h:w]" result2.jpg
The part inside the double-quotes is the interesting part. It is basically setting the extent of the image, like:
-extent 100x100
where 100 is the width and the height. Rather than that though, I am using a calculated expression which tests whether the height (h) is less than the width (w) using a ternary operator. That results in taking whatever is smaller out of the current height and width as the new height and width, So there are really two calculated expressions in there, with an x between them, similar to 100x100.
Note that this method requires ImageMagick v7 or better - i.e. it uses the magick command rather than v6's convert command. If you have v6, you need to use more steps. First, get the width and the height of the image, then choose the smaller of the two and then issue a convert command with the gravity and extent both set. In bash:
# Get width and height
read w h < <(identify -format "%w %h" scooby.jpg)
# Check them
echo $w,$h
272,391
# Set `n` to lesser of width and height
n=$w
[ $h -lt $n ] && n=$h
# Now do actual crop
convert scooby.jpg -gravity center -extent "${n}x${n}" result.jpg
If you have thousands to do, I would suggest using GNU Parallel if you are on macOS or Linux. If you are on Windows, sorry, you'll need a loop and be unable to easily use all your CPU cores.
I have not tested the following, so only try it out on a small, COPIED, sample of a few files:
# Create output directory
mkdir output
# Crop all JPEG files, in parallel, storing result in output directory
parallel --dry-run magick {} -gravity center -extent "%[fx:h<w?h:w]x%[fx:h<w?h:w]" output/{} ::: *.jpg
If the commands look good, remove the --dry-run part to do it for real.
If you're using ImageMagick v7, Mark Setchell has provided a simple method above (or below). If you're using IMv6, you can crop the largest center square from any image using a command lke this...
convert input.png -set option:distort:viewport "%[fx:min(w,h)]x%[fx:min(w,h)]" \
-distort affine "%[fx:w>h?(w-h)/2:0],%[fx:w<h?(h-w)/2:0] 0,0" output.png
That sets the output viewport size to the largest square you can crop from the input image. Then it adjusts the position of the input image so it is centered within that square viewport.
This command should work from a command prompt or script on most *nix systems. If you're using Windows, replace that continued line backslash "\" with a caret "^". If you're using a BAT script in Windows you'll also have to make all the single percent signs "%" into doubles "%%".
You can also simply change "convert" to "magick" to run this command using IMv7.
I find this easier to remember:
convert in.png -gravity Center -extent 1:1 out.png

imagemagick issue converting pdf form and overlaying pages

I'm using imagemagik to convert pdf's ( and other types ) to jpg.
Here is my command
"D:\\bc_458.pdf -resize 100x100 -flatten -quality 92 -background white D:\\tn_abc_458.jpg"
I am having 2 issues with this.
1) it doesn't work with pdf's that contains forms.
2) it is overlaying pages on top of each other. For example "bc_458.pdf" has 3 pages. tn_abc_458.jpg is created with all 3 layers overlaying each other.
ImageMagick is a (pixel) images processing software.
It doesn't process PDF input files itself -- it uses Ghostscript as a 'delegate' to convert PDF pages to pixel images first.
So, which version of Ghostscript have you installed? On Windows, run
gswin32c.exe -v
or
gswin64c.exe -v
on Mac OS X, Linux or Unix run:
gs -v
to find out.
What exactly are you problems with the PDF forms? 'It doesn't work with forms' doesn't tell me much...
The problem of overlaying the 3 page images over each other you can easily overcome: simply drop the -flatten part of the commandline (because that's what's responsible for the effect you observe). Furthermore, you could specify %04d as part of the output filename in order to have control of where ImageMagick puts the page number:
convert \
bc_458.pdf \
-resize 100x100 \
-quality 92 \
-background white \
page_%04d_bc_458.jpg"
I'm pretty sure that the command you quoted doesn't even do what you say it does: you forgot to put the convert command to the front of the line. ;-)

Crop and scale SVG to PNG using ImageMagick, without pixellation

I have an SVG with many polygons:
https://github.com/barrycarter/bcapps/blob/master/sample-data/current-temps.svg
that looks somewhat like this:
Cropping this and converting to PNG works fine:
convert -crop 100x100+200+150 current-temps.svg /tmp/exhb2.png
Cropping and scaling, however, fails:
convert -crop 100x100+200+150 -scale 1000x750 current-temps.svg /tmp/exhb3.png
How do I make ImageMagick "zoom into" the SVG before cropping?
(I realize ImageMagick can only read, not write, the SVG format, but
it should still be able to do what I want?)
EDIT/SOLVED:
Thanks, robermorales.
inkscape -z -e out4.png -w 1000 -h 1000 -a 200:200:400:400 current-temps.svg
(for example) worked like a charm.
I also realized that copying the SVG, tweaking the transform line:
<g transform="scale(3,3) rotate(-90) translate(-90,180)">
and then converting to PNG is another solution.
Try doing scale before crop.
However, doing that using inkscape cli is easier.
Sorry for no links, afk
Don't crop an SVG into PNG.
You can use viewBox to re-define the crop area then convert that SVG into PNG in highest solution as possible.
Check this post https://www.sarasoueidan.com/blog/svg-coordinate-systems/ explain what is viewBox and you will got my idea.
Proper ImageMagick syntax here is to read the input, then crop, then resize. See http://www.imagemagick.org/Usage/basics/#why Though that is not likely the issue. The issue is that -scale will replicated pixels and so make it blocky. You should replace -scale with -resize. That will be smoother, but blurry for the amount of magnification you are requesting. Try this command:
convert current-temps.svg -crop 100x100+200+150 -resize 1000x750 exhb3.png

Resources