Reputation: 6739
I want to convert image formats to JPG in a specific quality
The following command doesn't work for some reason , all i get is NULL
gm convert -quality 80 '/tmp/phpK31vNK' JPEG:'/tmp/phpK31vNK' && cat '/tmp/phpK31vNK'
However the following command works fine but graphicsmagick set the default quality which is 75
gm convert '/tmp/phpK31vNK' JPEG:'/tmp/phpK31vNK' && cat '/tmp/phpK31vNK'
Upvotes: 1
Views: 2307
Reputation: 207465
If you don't need the output file after you have cat
ed its contents, you can avoid creating it altogether as well as an unnecessary extra process to cat
it. You just tell GraphicsMagick to create a JPEG and send it straight to stdout
like this:
gm convert input.jpg -quality 80 jpeg:-
We can see it works by changing the quality and counting the bytes output like this:
# Low quality => small size
gm convert test.jpg -quality 60 jpeg:- | wc -c
9036
# Higher quality => larger size
gm convert test.jpg -quality 80 jpeg:- | wc -c
11513
Upvotes: 4
Reputation: 8869
Try:
gm convert image1 -quality 60 JPEG:image2
But if image1 is always a jpeg you can skip the JPEG:
specification:
gm convert image1 -quality 60 image2
Upvotes: 5