I’m trying to convert a 275 MB CBR file to pdf but the conversion is getting failed.
These are the steps I followed:
Command to unzip the rar: unrar e '/tmp/1676456470685.2727/6782.rar' /tmp/1676456470889.922
Command to convert the unzipped jpg images to pdf:
convert /tmp/1676456470889.922/*.jpg -profile /app/sRGB2014.icc -strip -set profile /app/sRGB2014.icc -compress jpeg -resize 1240.2x1753.95
-gravity Center -extent 1240.2x1753.95 -units PixelsPerInch -density 150 -repage 1240.2x1753.95 -bordercolor white -border 0 output.pdf
Error:
convert: cache resources exhausted `/tmp/1676456470889.922/OPSX-UK-028_Page_154.jpg' # error/cache.c/OpenPixelCache/3879.
convert: cache resources exhausted `/tmp/1676456470889.922/OPSX-UK-028_Page_155.jpg' # error/cache.c/OpenPixelCache/3879.
convert: cache resources exhausted `/tmp/1676456470889.922/OPSX-UK-028_Page_156.jpg' # error/cache.c/OpenPixelCache/3879.
convert: cache resources exhausted `/tmp/1676456470889.922/OPSX-UK-028_Page_001.jpg' # error/cache.c/OpenPixelCache/3879.
About system:
Host machine:
OS: Ubuntu 22.04.1 LTS
Memory: 64GB
ImageMagick is running in a docker container:
Container OS: Ubuntu 20.04.3 LTS
ImageMagick version: 7.1.0-62
Current ImageMagick resource policy:
<policy domain="resource" name="memory" value="16GiB"/>
<policy domain="resource" name="map" value="32GiB"/>
<policy domain="resource" name="area" value="24GB"/>
<policy domain="resource" name="disk" value="64GiB"/>
Related
I have a simple ImageMagick command that uses -contrast which is well-documented here: https://imagemagick.org/script/command-line-options.php#contrast
My command:
magick in.jpg -enhance -contrast -background white -quality 100 -resize 200x200^ -gravity center -extent 200x200 out.jpg
But I'm getting this error: magick: option has been replaced '-contrast', use "-level" at CLI arg 3 # warning/operation.c/CLISimpleOperatorImage/2078.
I'm using ImageMagick 7.0.9-7 Q16 x86_64 2019-12-02.
Features: Cipher DPC HDRI Modules OpenMP(3.1)
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib gvc heic jbig jng jp2 jpeg lcms ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib
So... why is it complaining about the -contrast option? It looks like -contrast is still there, and I don't see how -level is supposed to replace it. There's nothing I can find about -contrast being replaced/removed. It's very strange.
** UPDATE - even I can see right here in the code where that error message is generated. However, I can't see why it's doing that, and as I said, can't find anything in any documentation that implies -contrast should not be used.
I have a folder of images of varying sizes and quality. Is there a way with ImageMagic that I could automatically resize them to be no bigger 1100px x 1100px and less than 160kb. And not to re-size if they are smaller than those parameters. Also not to distort the image so it fits within but to only re-size so for example an image which is 2200px by 1000px would become 1100px by 500px.
I'm working on Ubuntu with ImageMagick 6.7.7-10.
Try this on a copy of your files:
mogrify -define jpeg:extent=160k -resize 1100x1100\> *.jpg
I am assuming your files are JPEG images. The command will largely work for other image types too, but it can only enforce the 160kB limit for JPEG files - not PNG, or TIFF etc.
Example
With version: ImageMagick 6.9.1-10 Q16 x86_64 2015-08-06
convert -size 2000x2000 xc:gray +noise random a.jpg
ls -lrt a.jpg
-rw-r--r-- 1 mark staff 6969601 21 Aug 18:28 a.jpg # <--- 7MB
mogrify -define jpeg:extent=160k -resize 1100x1100\> a.jpg
ls -lrt a.jpg
-rw-r--r-- 1 mark staff 147938 21 Aug 18:28 a.jpg # <--- 160kB
identify a.jpg
a.jpg JPEG 1100x1100 1100x1100+0+0 8-bit sRGB 148KB 0.000u 0:00.000
I am running a project with these software versions:
Paperclip 4.2.0
Rails 4.0.4
RHEL 6
convert -version => ImageMagick 6.8.9-9
convert -list configure =>
DELEGATES bzlib mpeg freetype jng jpeg lcms png ps tiff x zlib
and am getting this error while processing images through Paperclip.
Command :: convert '/tmp/a583e7c175d537c0442da246e5184fe120141205-17371-tvp3g.jpg' -auto-orient -resize "x85" -crop "85x85+21+0" +repage -alpha remove -strip '/tmp/a583e7c175d537c0442da246e5184fe120141205-17371-tvp3g20141205-17371-1ym7alo.png'
convert: UnrecognizedAlphaChannelType `remove' # convert.c/ConvertImageCommand/636.
Cocaine::ExitStatusError: Command 'convert '/tmp/a583e7c175d537c0442da246e5184fe120141205-17371-tvp3g.jpg' -auto-orient -resize "x85" -crop "85x85+21+0" +repage -alpha remove -strip '/tmp/a583e7c175d537c0442da246e5184fe120141205-17371-tvp3g20141205-17371-1ym7alo.png'' returned 1. Expected 0
Here is the command output:
from /home/proj/.rvm/gems/ruby-2.1.1/gems/cocaine-0.5.4/lib/cocaine/command_line.rb:96:in `run'
This error is caught on the Thumbnail processor in the make method.
The most confusing part of this is that I set a debugger when this error is caught, copied the src tmpfile to a permanent location outside my project and ran the exact same convert command as above and it runs successfully with exit status 0.
My next step in debugging would probably to bundle open cocaine, but I think there is something higher level going wrong... Hoping someone has run into this before?
I don't get the same problem on OSX.
You may have multiple installations of ImageMagick installed. You can check at the command line like so:
$ which -a convert
If you do have multiple installations, and Paperclip is referencing the "wrong" one, Paperclip allows you to specify the path to seek. As from the Paperclip README:
In development mode, you might add this line to config/environments/development.rb:
Paperclip.options[:command_path] = "/usr/local/bin/"
I've been at this all day. I'm trying to upload images to a Mediawiki and this is the error I get when ImageMagick tries to create the thumbnail:
Error creating thumbnail: convert: no decode delegate for this image format `/tmp/magick-11924QG1rRXzT948I' # error/constitute.c/ReadImage/552.
convert: no images defined `/tmp/s3thumb-cripEh' # error/convert.c/ConvertImageCommand/3127.
I setup a debug file for mediawiki and this is what I get in the log:
BitmapHandler::doTransform: creating 112x120 thumbnail at /tmp/s3thumb-cripEh using scaler im
BitmapHandler::doTransform: called wfMkdirParents(/tmp)
BitmapHandler::getMagickVersion: Running convert -version
wfShellExec: /bin/bash '/var/www/mediawiki-1.21.2/includes/limit.sh' ''\''/usr/local/bin/convert'\'' -version' 'MW_CPU_LIMIT=180; MW_CGROUP='\'''\''; MW_MEM_LIMIT=202400; MW_FILE_SIZE_LIMIT=102400; MW_WALL_CLOCK_LIMIT=180'
BitmapHandler::transformImageMagick: running ImageMagick: '/usr/local/bin/convert' -quality 80 -background white -define jpeg:size=112x120 '' -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 '/tmp/s3thumb-cripEh' 2>&1
wfShellExec: /bin/bash '/var/www/mediawiki-1.21.2/includes/limit.sh' 'OMP_NUM_THREADS='\''1'\'' '\''/usr/local/bin/convert'\'' -quality 80 -background white -define jpeg:size=112x120 '\'''\'' -thumbnail '\''112x120!'\'' -depth 8 -sharpen '\''0x0.4'\'' -rotate -0 '\''/tmp/s3thumb-cripEh'\'' 2>&1' 'MW_CPU_LIMIT=180; MW_CGROUP='\'''\''; MW_MEM_LIMIT=202400; MW_FILE_SIZE_LIMIT=102400; MW_WALL_CLOCK_LIMIT=180'
[thumbnail] thumbnail failed on ip-10-168-26-167: error 1 "convert: no decode delegate for this image format `/tmp/magick-11924QG1rRXzT948I' # error/constitute.c/ReadImage/552.
convert: no images defined `/tmp/s3thumb-cripEh' # error/convert.c/ConvertImageCommand/3127." from "'/usr/local/bin/convert' -quality 80 -background white -define jpeg:size=112x120 '' -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 '/tmp/s3thumb-cripEh' 2>&1"
LocalS3File::transform thumb:
LocalS3File::transform thumbTempPath: /tmp/s3thumb-cripEh, dest: wiki-images/thumb/1/19/5ovrDaU.jpg/112px-5ovrDaU.jpg
info:1
LocalS3File::transform return thumb: MediaTransformError Object
(
[htmlMsg] => Error creating thumbnail: convert: no decode delegate for this image format `/tmp/magick-11924QG1rRXzT948I' # error/constitute.c/ReadImage/552.<br />
convert: no images defined `/tmp/s3thumb-cripEh' # error/convert.c/ConvertImageCommand/3127.<br />
[textMsg] => Error creating thumbnail: convert: no decode delegate for this image format `/tmp/magick-11924QG1rRXzT948I' # error/constitute.c/ReadImage/552.<br />
convert: no images defined `/tmp/s3thumb-cripEh' # error/convert.c/ConvertImageCommand/3127.<br />
[width] => 112
[height] => 120
[url] =>
[path] =>
[file] =>
[page] =>
[responsiveUrls] => Array
(
)
[storagePath:protected] =>
)
Tried from the command line, copy pasted the command from the log (but used a test file):
convert -quality 80 -background white -define jpeg:size=112x120 '' -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 'logo.jpg'
but the process hangs. If I run:
sudo convert logo.png -quality 80 -background white -define jpeg:size=112x120 -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 logo.jpg
It works.
If I check DELEGATES, I have:
DELEGATES jng jp2 jpeg png ps tiff xml zlib
I tried increasing the default memory on media wiki to
$wgMaxShellMemory = 202400;
I feel like I've tried anything. Any ideas?
EDIT:
This is what I've discovered so far:
I'm pretty sure the shell wasn't executing the ImageMagick command because of the escaped backslashes in :
wfShellExec: /bin/bash '/var/www/mediawiki-1.21.2/includes/limit.sh' ''\''/usr/local/bin/convert'\'' -version' 'MW_CPU_LIMIT=180; MW_CGROUP='\'''\''; MW_MEM_LIMIT=202400; MW_FILE_SIZE_LIMIT=102400; MW_WALL_CLOCK_LIMIT=180'
Those ''\'' are causing the command to not run, and hence the "no decode" error. It can't decode, because the file is not there. I've traced wfShellEec to GlobalFunctions.php. The wfShellExec function is at around line 2778 on my file.
In the if ( php_uname( 's' ) == 'Linux' ) block there is:
escapeshellarg( $cmd )
I removed the escapeshellarg() function and just left the $cmd on its own.
Tried uploading again, the error is gone, the files are created, but now the thumbnail files are 0 bytes.
Any ideas?
In the following, the empty string parameter '' represents what is supposed to be the input image:
convert -quality 80 -background white -define jpeg:size=112x120 '' -thumbnail '112x120!' -depth 8 -sharpen '0x0.4' -rotate -0 'logo.jpg'
When you ran sudo convert logo.png ... from the command line it worked because you had an input image (logo.png), but inside MW the source image parameter was missing. So the problem here is not with convert, ImageMagick naturally cannot convert an image that doesn't exist. The problem is that MW fails to supply the source image file name.
If your case is like mine, the empty '' image source parameter could trace back to permissions in the images directory. Make sure this directory and all its subdirectories are rwx by the server process. Once I opened up everything in this dir to the server, the errors went away and the images and thumbnails appeared perfectly.
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.