convert.exe: invalid argument for option `-crop': - ruby-on-rails

convert.exe: invalid argument for option `-crop': '230x53+64+157'-auto-orient # error/convert.c/ConvertImageCommand/1154. [paperclip] An error was received while processing: #
I have referred:
http://railscasts.com/episodes/182-cropping-images
to crop my image.

Related

"gs: symbol lookup error: /lib64/libgs.so.9: undefined symbol: FT_Property_Set" Error when converting .ai file to .png with ghostscript 9.25

I'm using ImageMagick with ghostscript 9.25 to convert images. When I try to convert .ai file to .png with image magic I'm getting the below error in command line
My command ./convert /home/sample_ai_file2.ai /home/ai_out.png
gs: /opt/software/alfresco-one/common/lib/libtiff.so.5: no version information available (required by /lib64/libgs.so.9)
gs: /opt/software/alfresco-one/common/lib/libjpeg.so.62: no version information available (required by /lib64/libgs.so.9)
gs: symbol lookup error: /lib64/libgs.so.9: undefined symbol: FT_Property_Set
.convert.bin: NoImagesForWrite '-write' '/home/sshtest/ai_out.png' at CLI arg 2 # error/operation.c/CLINoImageOperator/4769.
.convert.bin: NoImageForProperty "%w" # warning/property.c/GetMagickPropertyLetter/2561.
.convert.bin: UnknownImageProperty "%w" # warning/property.c/InterpretImageProperties/3499.
.convert.bin: NoImageForProperty "%h" # warning/property.c/GetMagickPropertyLetter/2449.
.convert.bin: UnknownImageProperty "%h" # warning/property.c/InterpretImageProperties/3499.
.convert.bin: NoImageForProperty "%m" # warning/property.c/GetMagickPropertyLetter/2480.
.convert.bin: UnknownImageProperty "%m" # warning/property.c/InterpretImageProperties/3499.
Does any one know the reason for this error ? I can convert all the other image types without any issue.
I was able to find the cause for the above mentioned issue. The error was due to having two versions of GS installed in my system.
When I install ImageMagick, GS 8.64 is also automatically installed by default, then I have again manually installed GS 9.25.
Removing the GS 9.25 resolved my issue.

ImageMagick Identify not working

I'm using ImageMagick along with paperclip to upload images in a RoR application. The problem is that the command 'identify' is causing trouble. My app throws the following error "Image Paperclip::Errors::NotIdentifiedByImageMagickError". Looking deep into the logger, I found:
Command :: identify -format '%wx%h,%[exif:orientation]' "C:/Users/<...>" 2>NUL
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' "C:/Users/<...>" 2>NUL
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
And then I tried to wirte the problematic commad into my cmd and it throws
identify: unknown image property "%[exif:orientation]" # warning/property.c/InterpretImageProperties/3904
I'm using Windows and I have installed ImageMagick 7.0.7 with legacy options.
The problem isn't that I don't know how to get the orientation. The problem is that when I upload an image and try to create the 'profiles'
has_attached_file :image,
styles: { thumb: ["64x64#", :jpg],
original: ['500x500>', :jpg] },
convert_options: { thumb: "-quality 75 -strip",
original: "-quality 85 -strip" }
Paperclip makes an automatic call to that command to get the orientation and my console does not seem to recognize that command.

ImageMagick: split multipage 32 float TIFF image

I'm trying to convert 32-bit multipage TIFF image to several single TIFF images.
Command from here
convert -depth 32 temp.tif single%d.tif
convert: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 42113 (0xa481) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Sorry, can not handle images with 32-bit samples. `temp.tif' # error/ti
ff.c/TIFFErrors/565.
convert: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 42113 (0xa481) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Sorry, can not handle images with 32-bit samples. `temp.tif' # error/ti
ff.c/TIFFErrors/565.
convert: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 42113 (0xa481) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Sorry, can not handle images with 32-bit samples. `temp.tif' # error/ti
ff.c/TIFFErrors/565.
convert: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 42113 (0xa481) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Sorry, can not handle images with 32-bit samples. `temp.tif' # error/ti
ff.c/TIFFErrors/565.
convert: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 42113 (0xa481) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Sorry, can not handle images with 32-bit samples. `temp.tif' # error/ti
ff.c/TIFFErrors/565.
convert: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 34737 (0x87b1) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Unknown field with tag 42113 (0xa481) encountered. `TIFFReadDirectory'
# warning/tiff.c/TIFFWarnings/905.
convert: Sorry, can not handle images with 32-bit samples. `temp.tif' # error/ti
ff.c/TIFFErrors/565.
Seems it can't work with 32-bit images by default convert: Sorry, can not handle images with 32-bit samples.
convert -version
Version: ImageMagick 7.0.2-6 Q16 x64 2016-07-30 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pa
ngocairo png ps rsvg tiff webp xml zlib
Is there any way to do it with ImageMagick?
Mmmm, I have tried Q16 and Q32, HDRI and Non-HDRI versions of ImageMagick with most combinations of most of these options:
-define quantum:format=floating-point
-depth 32
-define tiff:ignore-tags=42113,34737,34736
-define quantum:format=signed
and I can't get anywhere either!
I did have some success, I think with vips which is a fairly light-weight, easily installed package but it kind of depends what you want to do with the data afterwards:
Either you could convert each "page" straight from TIF to 32-bit PNG with this:
vips im_vips2png temp.tif:1 1.png
vips im_vips2png temp.tif:2 2.png
Or, you could go the long way round via PPM format:
# Convert first "page" in TIF to vips format
vips im_tiff2vips temp.tif:1 1.v
# Convert second "page" in TIF to vips format
vips im_tiff2vips temp.tif:2 2.v
... and so on for all 5 pages.
Then I can convert those to float PPMs with vips
vips ppmsave 1.v 1.ppm
vips ppmsave 2.v 2.ppm
And now ImageMagick can process the PPM files:
convert 1.ppm a.png
It kind of depends what you want to do next...
The tiff format is highly extendable, and I would suggest finding/researching the proprietary software used to generate the images.
Following Mark's fantastic answer, I was able to research the following...
Private Tiff Tags
GeoTIFF
0x830e - ModelPixelScaleTag
0x8482 - ModelTiepointTag
0x87af - GeoKeyDirectoryTag
0x87b0 - GeoDoubleParamsTag
0x87b1 - GeoAsciiParamsTag
GDAL library
0xa481 - GDAL_NODATA
TIFF Errors
convert: Sorry, can not handle images with 32-bit samples. `temp.tif' # error/tiff.c/TIFFErrors/564
This message comes from libtiff library that was linked to by ImageMagick. It simply doesn't support TIFFTAG_BITSPERSAMPLE of 32-bit per sample. Here's a code-snippet of TIFFRGBAImageBegin method used by the tiff library.
TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);
switch (img->bitspersample) {
case 1: case 2: case 4:
case 8: case 16:
break;
default:
sprintf(emsg, "Sorry, can not handle images with %d-bit samples",
img->bitspersample);
return (0);
}
Alternative tiffsplit
If the task is just to spite the layers into isolated images, perhaps the tiffsplit will work...
tiffsplit temp.tif single_
... which will generate single_aaa.tif, single_aab.tif, & etc.
However the last layer of the image appears corrupt :(

When I try to do a batch magick convert -flatten command on a directory, it fails

I'm, trying to flatten a whole directory of .png images to have a white background.
The following command works on a single file:
magick convert -flatten "c:\Users\LibrarySurface2\OneDrive\Pictures\2016-08-09 archive of coworking space feedback\20151214 115702.png" "c:\Users\LibrarySurface2\OneDrive\Pictures\2016-08-09 archive of coworking space feedback\20151214 115702-white.png"
...however when I try to run it against the whole directory (1300 or so images) using the following command:
magick convert -flatten *.png *-w.png
It fails out with a bunch of these, and then stops running because of "too many exceptions" any thoughts on what could be causing this?
convert: Expected 3949 bytes; found 2684 bytes .\20160426 114948.png' # warning/png.c/MagickPNGWarningHandler/1683.
convert: Read Exception.\20160426 114948.png' # error/png.c/MagickPNGErrorHandler/1650.
convert: corrupt image .\20160426 114948.png' # error/png.c/ReadPNGImage/4029.
convert: Expected 4585 bytes; found 929 bytes.\20160429 145040.png' # warning/png.c/MagickPNGWarningHandler/1683.
convert: Read Exception .\20160429 145040.png' # error/png.c/MagickPNGErrorHandler/1650.
convert: corrupt image.\20160429 145040.png' # error/png.c/ReadPNGImage/4029.
convert: Expected 8192 bytes; found 8037 bytes .\20160504 165938.png' # warning/png.c/MagickPNGWarningHandler/1683.
convert: Read Exception.\20160504 165938.png' # error/png.c/MagickPNGErrorHandler/1650.
convert: corrupt image `.\20160504 165938.png' # error/png.c/ReadPNGImage/4029.
Make a backup first, then use mogrify instead:
mogrify -flatten *.png
Explanation: In general, use the convert command when you want one output file and mogrify when you want multiple output files.

How to resize already uploaded Paperclip images to s3 using reprocess? (Rails)

I have a model:
class PropertyImage < ActiveRecord::Base
has_attached_file :picture,
storage: :s3,
s3_credentials: CONFIG['s3'],
s3_protocol: (Rails.env.development? ? "http": "https"),
styles: {
thumb: '100x100>',
large: '633x460>',
medium: '301x240>'
}
end
I'm using Rails (4.0.1), cocaine (0.5.4) and paperclip (3.5.4).
I want to migrate old images (with no thumb, large and medium) and resize each, so I created a rake script:
namespace :migrate_images do
desc "Resize Images in PropertyImage"
task start_migration: :environment do
PropertyImage.not_migrated.find_each do |pi|
ImageConverter.perform(pi)
end
end
end
And ImageConverter class:
class ImageConverter
def self.perform(pi)
begin
pi.picture.reprocess!
pi.update_attributes!({migrated: true})
puts "PropertyImage [#{pi.id}] has been migrated."
rescue Exception => e
puts "PropertyImage [#{pi.id}] has an error. #{e}"
end
end
end
Now when I run the script I keep getting the following error:
⇒ bundle exec rake migrate_images:start_migration
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
PropertyImage [11] has an error. Validation failed: Picture Paperclip::Errors::NotIdentifiedByImageMagickError, Picture Paperclip::Errors::NotIdentifiedByImageMagickError, Picture Paperclip::Errors::NotIdentifiedByImageMagickError
PropertyImage [12] has an error. Validation failed: Picture Paperclip::Errors::NotIdentifiedByImageMagickError, Picture Paperclip::Errors::NotIdentifiedByImageMagickError, Picture Paperclip::Errors::NotIdentifiedByImageMagickError
Please note that I read similar articles and added the following to the end of application.rb:
Paperclip.options[:command_path] = "/usr/local/bin/identify"
And I made sure I have imagemagick installed:
⇒ brew install imagemagick
Warning: You have an outdated version of /usr/bin/install_name_tool installed.
This will cause binary package installations to fail.
This can happen if you install osx-gcc-installer or RailsInstaller.
To restore it, you must reinstall OS X or restore the binary from
the OS packages.
Warning: imagemagick-6.8.9-7 already installed
Any help would be highly appreciated.
Please note if I try to reproduce the problem using rails console:
>> p = Property.find(93746)
>> p.property_images.each do |pi|
?> pi.picture.reprocess!
>> end
PropertyImage Load (1.4ms) SELECT "property_images".* FROM "property_images" WHERE "property_images"."invalid_image" = 'f' AND "property_images"."property_id" = $1 ORDER BY "property_images"."apartment_main" DESC [["property_id", 93746]]
[paperclip] copying /property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg to local file /var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/T/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg
[AWS S3 200 1.212736 0 retries] get_object(:bucket_name=>"my_bucket_development",:key=>"property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg")
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/T/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/T/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/T/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
[paperclip] saving /property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg
[AWS S3 200 0.293473 0 retries] put_object(:acl=>:public_read,:bucket_name=>"my_bucket_development",:content_length=>0,:content_type=>"image/jpeg",:data=>Paperclip::AttachmentAdapter: 722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg,:key=>"property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg")
(0.2ms) BEGIN
(0.2ms) ROLLBACK
Make sure that the format you are trying to upload is supported by Imagemagick on the server you are using.
To make sure of this, use this command:
convert -list format
If the format you are trying to upload with Paperclip is not in the list, you need to install the libraries needed and then reinstall/recompile Imagemagick.
Here is given an example of how to do that on a Unix machine. To install the jpg library, it is used the command:
yum install libjpeg libjpeg-devel
How to install the library and reinstall/recompile Imagemagick depends on which OS you use and on which image format you need.

Resources