sidekiq + carrierwave + minimagick - carrierwave

We're running a sidekiq job that does some carrierwave processing of some images.
Our our sidekiq box when running as the ubuntu user the job seems to do it's thing.
However when running under monit the job will fail with this error coming out of minimagick:
Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: Command ("mogrify -format jpg -alpha remove -quality 85 /tmp/mini_magick20140711-31558-7ew026.png[0]") failed: {:status_code=>1, :output=>"mogrify: UnrecognizedAlphaChannelType `remove' # error/mogrify.c/MogrifyImageCommand/3820.\n"}
Same images being processed, same directories where the cached images are being put, really have no idea what's going on. Why would it work outside of monit but not within it?
Ubuntu 12.04
mogrify version 6.8.9-3

Related

Batch-converting of INTA images

I have a large number of images in the INTA format, an old SGI standard. INTA is a grayscale image with an alpha channel. All of these need to be converted to TGA files. The problem is that neither ImageMagick nor PIL/Pillow seem to be able to parse them correctly. ImageMagick can read and export them but doesn't seem to understand the alpha channel, and PIL fails to open them, with the error ValueError: Unsupported SGI image mode. The one thing that I've found that reads them successfully is GIMP:
An ideal solution would be one that is easy to invoke from a script.
For reference, here is one of the images in question (the same one seen in the screenshot): https://www.dropbox.com/s/8hoppdgtuqxsy26/girder01.inta?dl=0
It seems GDAL is able to read your image and I converted it to a greyscale+alpha PNG using:
gdal_convert YOURIMAGE.sgi result.png
You can easily get to TGA from there.
I am assuming the batching is not an issue, but it would look something like this in bash:
mkdir -p OUTPUT
for f in *.inta ; do
gdal_translate "$f" OUTPUT/"$f"
done
I had all sorts of trouble installing GDAL on macOS so I just used docker like this:
docker run --rm -v /Users:/Users osgeo/gdal:alpine-normal-latest gdal_translate /Users/mark/Downloads/image.sgi /Users/mark/Downloads/result.png

Rails + Passenger: Can't execute shell commands

I've setup Apache + Rails + Passenger and the app loads correctly (for the most part). The application uses Tesseract and GS to convert PDFs into images and then take their text and insert it into the database.
When I test the application using rails s, everything functions normally, but when I try to run some of the functions from the passenger instance, I get the following error in my apache log:
App 14107 stderr: sh: tesseract: command not found
The error occurs for the following code:
%x(gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -sOutputFile="page%03d".png #{self.doc.path})
%x(for f in page*.png ; do tesseract $f $f.out; done)
There is nothing in my rails production.log file that indicates any errors.
I'm running CentOS 6 and I built my tesseract using this guide:
https://www.simpleservers.co.uk/clients/whmcs/knowledgebase/600/Install-Tesseract-OCR-libs-from-sources-in-Centos.html
The user that passenger runs as can also run the command tesseract. I checked in its console, but for some reason, passenger can't run it. Do I need to enable it for the apache user somehow?
Thanks
Thanks to shellter for pointing me in the right direction. This is what fixed the issue for me:
Apache couldn't call tesseract, so I had to add it to its path. Based on this answer (How to add path to Apache), I went to /etc/sysconfig/httpd (this is CentOS specific) and added the line:
export PATH=<the path>
To get the path, I just ran this in the console:
env
And took the output for the PATH.

Rmagick Fails To Manipulate PNG

Following the Railscast episode on CarrierWave:
I installed ImageMagick on Mountain Lion via homebrew, exported the following path:
export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig:$PKG_CONFIG_PATH"
Symlinked the following:
ln -s /usr/local/include/ImageMagick/wand /usr/local/include/wand
ln -s /usr/local/include/ImageMagick/magick /usr/local/include/magick
And installed rmagick via bundler.
In my uploader I have the following:
include CarrierWave::RMagick
version :thumb do
process :resize_to_limit => [85, 85]
end
Which creates thumbnails just fine, but not for png files. I've tried a handful of png images and it always fails with this error:
Failed to manipulate with rmagick, maybe it is not an image? Original Error: no decode delegate for this image format `<path>/public/uploads/tmp/20121022-2133-9885-3333/thumb_cat_vs_internet.png' # error/constitute.c/ReadImage/544
jpeg images work just fine.
EDIT
identify -list format | grep -i png returns nothing, indicating the png decode delegate is probably missing. Now what?
After determining the PNG delegate is not installed (using identify -list format), you should try uninstall/reinstalling ImageMagick as something was likely missed by the installer.

ImageMagick and Paperclip problem

I've got a problem with ImageMagick and Paperclip.
I'm using on localhost rails3, ruby1.9.2, imagemagick 6.5.8 and paperclip as gem in version 2.3.8.
On production (server) I have rails3, roby1.9.2, imagemagick 6.6.7-4 and the same paperclip as above.
When uploading photos on localhost everything is fine.
But on server my problem appear. It gets error:
[paperclip] identify -format %wx%h
'/tmp/stream20110204-15633-3wdd5s.jpg[0]'
2>/dev/null
[paperclip] An error was received
while processing:
Paperclip::NotIdentifiedByImageMagickError:
/tmp/stream20110204-15633-3wdd5s.jpg
is not recognized by the 'identify'
command.
(the last paragraph is in brackets but I don't know how to avoid hiding it).
Anyone know what's going on?
edit:
All the time I search for some solve and seems that it is problem with ImageMagick. I uploaded some .jpg file on server and try run command "identify file.jpg" and... there is an error:
identify: no decode delegate for this image format `file.jpg' # error/constitute.c/ReadImage/532.
hmm...
Possibly Paperclip doesn't know where to find the ImageMagick binaries. Have you tried setting up an initializer for Paperclip in config/initializers/paperclip.rb ?
Set:
Paperclip.options[:image_magick_path] = "/usr/bin"
On your system you might need /usr/local/bin, or something else entirely. You can find out where the 'identify' binary and other ImageMagick binaries are located by typing:
which identify
If the answer is /usr/bin/identify, then you know to set image_magick_path to /usr/bin
If adding Paperclip.options[:command_path] = "/usr/local/bin/" doesn't work try installing ImageMagick with common delegates:
mkdir /sources cd /sources
wget
ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar xvfz ImageMagick.tar.gz
cd ImageMagick-6.6.7-8
Here comes the part makes difference
./configure --disable-static
--with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8
make
sudo make install

ImageMagick is not processing images, but gives no errors

My problem is is that paperclip saves the attachments appropriately, and I assume imagemagick is doing something right. With no errors returning, the images never finish processing.
Does anyone know a way to see what's backgrounding?
Or specifically a way to review imagemagick's processes?
tail -f log/delayed_job.log for "backgrounding"
And imagemagick's processes can be seen in your regular production log.
tail -f log/production.log

Resources