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.
Related
I have an app icon for iOS but Apple doesn't allow alpha to be in the image. How to remove this alpha channel? I only have the png image with me I don't have the source file as my friend did the image for me.
The accepted answer to export to JPG, then back to PNG is not recommended.
It's an extra step in the process (2 exports)
JPG is lossy, so you will lose some image data
Here's a super fast and easy way to do this without the extra export or saving to (lossy) JPG:
Using Preview app (Mac):
Open the image
Command-Shift-S to Duplicate (creates a copy)
Command-S to Save
Deselect the "Alpha" checkbox
Delete " copy" from filename (including the space)
This will overwrite your original, if you want to keep the original, just leave "copy" in the name
Save
Click 'Replace' to confirm you want to overwrite the original
Only necessary if you are overwriting your original
if you need remove all alpha channel from directory with icons use this command:
for i in `ls *.png`; do convert $i -background black -alpha remove -alpha off $i; done
if you have Mac OS Mojave and had "convert command not found"
brew install imagemagick
To install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Assuming you don't have another image editor, then you can open it in Preview on your Mac, and use the Export option to resave it in a different format- to ensure you get rid of the alpha channel, it might be best to export to JPG (best quality), then open that and export it as a PNG again.
Having said that, I suspect you're probably OK submitting an icon with a transparency channel as long as there's no actual transparency.
If you are using the Preview app, there's no need to export then re-export between jpg and png, just choose export and below the filetype (PNG) you will see an alpha checkbox, unset it and save.
You can try imagemagick (also easily resize for different sizes):
convert in.png -background black -alpha remove -alpha off -resize 1024x1024 out.png
There's no need to export the image to jpg first. You can uncheck the checkbox for the alpha channel and export directly from a png to a png without alpha channel in the preview app.
Just got the the following error when trying to upload my app to the iTunes app store:
iTunes Store Operations Failed
ERROR ITMS-90717: "Invalid App Store Icon. The App Store icon in the asset catalog in 'MyApp.app' can't be transparent nor contain an alpha channel."
I confirmed that my app store icons did include the alpha channel by locating the asset in Finder and looking up its info (⌘+i). Underneath More info, it showed:
Alpha channel: Yes
Found the solution above to use Preview to remove the alpha channel by exporting it with the Alpha checkbox unchecked, but figured a way to batch export them since I had 18 assets I needed to strip the alpha channel from.
The way I got batch exporting to work was to select all my app icon assets in finder > right click > open (or open with preview)
All of the assets will now appear in the same window. Select all (⌘+a), and then select File > Export Selected Images… > Expand Options > uncheck the Alpha checkbox > Choose (your destination folder)
Done! All your images are now exported with the alpha channel stripped off.
To remove alpha channel from png:
on Mac:
Preview version 9.0 (macOS Sierra) can remove the alpha channel if you export or save the image.
Preview version 10.0 (944.2) (macOS High Sierra) does not remove the alpha channel.
Both Export and/or Save does not remove the alpha channel from the image.
Well, since you're on a Mac, next time you probably just want to use Automator. Convert the image to BMP (lossless) and back to PNG. Let it save and voila...
I put Nikita Pushkar's very nice solution into a shell script that converts all iOS icons found in res/icon/ios:
It uses brew to install imagemagick if not available, so I guess it will run only on Mac.
#! /usr/bin/env bash
#
# remove alpha channel from PNG images when App Store upload fails
#
# taken from https://stackoverflow.com/a/52962485 - #Nikita Pushkar
#
# make sure to have brew installed, see https://brew.sh:
# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#
# make sure to have imagemagick installed, see https://imagemagick.org:
# brew install imagemagick
#
if command -v convert; then
echo "imagemagick seems to be installed"
else
echo "imagemagick not installed, trying to install ..."
if command -v brew; then
echo "brew is installed, using it"
else
echo "brew not installed, trying to install ..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install imagemagick
fi
for i in `ls res/icon/ios/*.png`;
do
echo "convert $i"
convert $i -background white -alpha remove -alpha off $i;
done
I've used a tool (anyone that allows to convert images to any format from any format). Here are the steps:
1. Transform all png images to jpeg
2. Transform the jpeg images back to png.
Try to upload a new build.
With this Lab/TIF image (amongst others):
http://cl.ly/3D2g0M1R4036
Running convert file1.tif file1.jpg results in this distorted result when run on my server, which is Ubuntu 12.04 LTS. This is running ImageMagick 6.6.9-7:
http://cl.ly/image/3P253v2y3L2x
The same command run locally on my Mac, does not have the same issue. I've tested this locally with the version of ImageMagick installed by HomeBrew (6.8.0-10) as well as 6.6.9-7 manually compiled to compare as closely with the server as possible.
I had suspected that it might have been the version of libtiff, as the Mac has 4.0.3, and the server has 3.9.5, however I've just run a test on a fresh Ubuntu install with latest ImageMagick, and libtiff 3.9.5, and the problem is still present.
Anything obvious?
Running tiffinfo states that the colorspace of "file1.tif" is CIELab. Ubuntu's ImageMagick, installed through apt-get, will have Lab -- but not CIELab. This can be confirmed by running the following command between the two systems.
identify -list colorspace
I'm not exactly sure what the difference between the two colorspaces are (something about chromatic value,) but that would contribute to the illumination your experiencing.
A solution would be to install ImageMagick from source on you Ubuntu server/machine (which will include CIELab). Other people have experienced related issues; which, resolved after building from source.
With apt-get
Uninstall ImageMagick
Install the development packages for each dependent library (ie libtiff-dev)
Follow ImageMagick's documentation
Update:
You can also explicitly set the colorspace with the -set option. Also add the -verbose options to evaluate what ImageMagick is doing.
convert -verbose file1.tiff -set colorspace CIELab -colorspace sRGB file1.jpg
# Output
file1.tif TIFF 1451x1865 1451x1865+0+0 8-bit CIELab 1.326MB 0.110u 0:00.109
file1.tif=>file1.jpg TIFF 1451x1865 1451x1865+0+0 8-bit sRGB 411KB 0.820u 0:00.840
I'm getting the following error in my development.log
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /tmp/stream28514-0 is not recognized by the 'identify' command.>
And i've googled about this error and i found out that many people have solved this by adding this line
Paperclip.options[:command_path] = "/usr/local/bin"
However, i still get the same error even after adding that line! I've tried everything possible!
Any help would be highly appreciated!
Regards,
Punit
The Paperclip.options[:command_path] setting is for the location of your ImageMagick executables (in this case identify). Try running which identify and setting the option to be the directory that is returned. If that command doesn't return anything, make sure that ImageMagick is properly installed.
Here is what worked for me...
I uninstalled the imagemagick that i installed from the official webpage.
I reinstalled it from sudo apt-get install imagemagick
then i did write Paperclip.options[:command_path] = "to/correct/path"
THE PROBLEM HERE WAS...
when i ran "which identify" it appearde that the path was "usr/local/bin/identify"
it means that we I was supposed to put as a path "usr/local/bin" as my path.
BUT IT DIDN'T WORKED!
I surprisingly found that i identify was also in the "usr/bin" path. So i changed:
"usr/local/bin" to "usr/bin"
And that was all!
It means that it cannot find ImageMagick's executable identify on the location you specified in Paperclip.options[:command_path] (in your case /usr/local/bin).
This is tipically caused by two reason:
It might be that you actually did not installed ImageMagick.
SOLUTION: install it:
For MAC: sudo port install ImageMagick (which installs the binary release)
For UBUNTU: sudo sudo apt-get install imagemagick
It might be that the location where you installed ImageMagick is not /usr/local/bin but something else.
SOLUTION: find where it is installed, or via the command:
which identify (in case that identify is in the current PATH, as it should be)
or via a raw find through the file system:
find / -name identify
Anyway, the usual location for those file in Ubuntu should be /usr/bin
There are two possible problems:
Image Magick is not installed or broken
Paperclip is not able to find Image Magick
Let's take them one at a time:
1. Check you have Image Magick installed and it is working
Type:
identify
at the command line, it should work. If it isn't found, or fails to work, install Image Magick. Did this fix it? If not, continue:
2. Help Paperclip find Image Magick
Type:
which identify
at the command line to get the path to the identify command. Now, in production.rb, add the following line to the configuration block:
Paperclip.options[:command_path] = "/usr/bin"
Restart your server. That should fix it.
usr/bin worked me (Fedora 14 core)
Try running the identify command in the command line and see if that gives you some error message. I found out that my server was missing some delegate libraries.
identify example.jpg
I installed RefineryCMS on my server(CentOs 5.5) and everything works fine except uploading images. It will show an error like:
NoMethodError in Refinery::Admin::ImagesController#create
undefined method `downcase' for nil:NilClass
I installed ImageMagick by typing:
sudo yum install ImageMagick
I searched online and it seems ImageMagick installed by yum is too old (Version 6.2.x)
Then I removed it, successfully installed ImageMagick v6.7.7 from source code.
Now when I try to upload an image, refinery shows:
Dragonfly::Shell::CommandFailed in Refinery::Admin::ImagesController#create
Command failed (identify '/tmp/RackMultipart20120628-29239-70xr45') with exit status 127
However, if I run that command "identify '/tmp/RackMultipart20120628-29239-70xr45'" in the command line, it will show the result without any error. It seems that Dragonfly can not pick up my installation of the lastest version of ImageMagick. Could any one tell me how to configure it ? Or should I upgrade my centOS ?(I wish not)
Well, I have struggled with this issue for more than one week.
I also asked this question in Github and finally got the solution there.
see: https://github.com/resolve/refinerycms/issues/1781#issuecomment-6823858
Since this problem is caused by that Dragonfly can not find imagemagick.
You can try add the following code to config/application.rb
initializer 'override-image-magick-paths', :after => 'attach-refinery-images-with- dragonfly' do
app=Dragonfly[:refinery_images]
app.configure_with(:imagemagick)
app.configure do |c|
c.convert_command = "/usr/local/bin/convert" # defaults to "convert"
c.identify_command = "/usr/local/bin/identify" # defaults to "identify"
end
end
Modify the path according to your imagemagick installation.
You can use which command to find the path. e.g. which convert
However, this still doesn't work for me.
And finally, toymachiner62 find a solution which is simple and works perfect.
That is to use symbolic link:
$ cd /usr/bin
$ ln -s /usr/local/bin/convert convert
$ ln -s /usr/local/bin/identify identify
modify the /usr/local/bin/convert paths to you installation as well.
This looks like my /usr/local/bin path is not in my $PATH, but actually it is.
Dragonfly just seems can not find it anyway.
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