Convert favicon.ico to png to using ImageMagick Procedurally - imagemagick

It looks like ImageMagick does not always convert a single favicon.ico file to a predictable single png file - for some favicon's, it generates a bunch of other favicon-01.png, favicon-02.png, etc... Is there a way to figure out which one's the actual converted favicon you want - or figure out how many got generated, to delete the unwanted ones?

I came across with the same problem while I was trying to convert blogger's favicon and I solved it by using -flatten parameter of Imagemagick like this:
convert "favicon.ico" -thumbnail 16x16 -alpha on -background none -flatten "favicon.png"

This likely happens because there are multiple images in the icon file - this is to provide differet resolutions for different contexts. Presumably you'd want to run a search in the target directory for favicon*.png, then check the dimensions of each one to find the one you wanted (deleting the others as you go).

I guess some of these are animated gifs. You can take the first one as described here:
http://www.imagemagick.org/script/command-line-processing.php
i.e.:
$magick> convert 'images.gif[0]' image.png
I don't have ImageMagic installed, but you might try the above for all favicon.ico, it might work fine.
Otherwise, you would probably need to write a script to check for favicon-01.png and, if it exists, rename it to favicon.png and delete favicon-*.png (provided you don't have anything else named like that in the working folder).

Related

Edit Photos via Photoshop on a server

I wart to create a web app where a user enters certain data via a form and then receives a custom rendered image. The image is from a smart object in a psd. It's kind of like a mock-up which definitely requires needs some photoshop filters to be properly rendered.
This should all happen in real time and should be doable from my understanding since the rendering of a single images doesn't need much computing power
I've done some research and haven't really found a solution the matches my problem. Is it necessary to run Photoshop on a server and then remotely run a photoshop script and then upload the generated image somewhere else?
I've used The After Effects Plugin Template by DataClay in the past which offers similar functionality but for video.
Looking forward to hearing your ideas.
Thanks
You can use the Dataclay plugin to handle still image exports out of After Effects. Make a single-frame duration composition in After Effects and rig the layers with the Templater plugin. Then use the PNG Sequence output module to render out a single frame.
From Dataclay's forums:
Exporting
A few extra steps are required to correctly render a project file as a PNG sequence using Templater. By default, a file rendered as a PNG sequence will have the frame number appended to the end of the file name, i.e.:
filename.png00000, filename.png00001, filename.png00002, etc.
In order to designate where in the filename the frame number should be added, we’ll need to use the output column. First, add a column named output to your data source. Next, add a filename with a set of brackets with five # signs to designate where the frame numbering should be added. For example:
filename[#####] would result in filename00001.png
or
[#####]filename would result in 00001filename.png

ImageMagick: Convert selective images to Multipage PDF without using external text file?

Let's say I have a directory with 5 TIFF files in it and I want to convert some of them to a multipage PDF, but that there are other TIFS in the same directory that I do not want in the same PDF.
In other words, I want to convert file1.TIF, file2.TIF, file3.TIF --> foo.pdf, but I want to ignore file4.TIF and file5.TIF located in the same folder.
It would seem from the documentation that the only way to do this is to provide ImageMagick with a text file listing out the files and then point to it when calling the program, as in:
convert #FilesToConvert.txt C:\foo3.pdf
Is there no way to make the call inline though, so that I don't have to create a separate text file for each conversion?
Thanks in advance!
You should be able to use:
convert file1.TIF file2.TIF file3.TIF foo.pdf

Combine multi-page PDFs into one PDF with ImageMagick

I am trying to use ImageMagick (6.8.0) to combine several multi-page PDFs into a single PDF. This command:
$ convert multi-page-1.pdf multi-page-2.pdf merged.pdf
Returns merged.pdf, which contains the first page of multi-page-1.pdf and the first page of multi-page-2.pdf.
This command:
$ convert multi-page-1.pdf[2] multi-page-2.pdf[2] merged.pdf
Returns merged.pdf, which contains the third page of multi-page-1.pdf and the third page of multi-page--2.pdf.
I would like to merged.pdf to contain all of the pages of each multi-page pdf. I have so far not found a way of telling the convert command to use a range of pages, although I have tried adding [0-1] and [0,1] at the end of the filenames.
Interestingly, this ghostscript command (which I found via StackOverflow but cannot re-find) does work as I would like it to:
$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf multi-page-1.pdf multi-page-2.pdf
The problem is, the ImageMagick 'convert' command takes urls as inputs and ghostscript does not, and I need my program to take url input rather than file paths.
Is it possible to get the result of the above ghostscript command using ImageMagick?
Why don't you use pdfunite?
Example:
$ pdfunite 1.pdf 2.pdf 3.pdf merged.pdf
I asked this question on an internal company forum, and the conclusion was that there is no way to do the type of document merging we would like to do with ImageMagick without first downloading the file the the local filesystem.
For those of you using Heroku, we are taking advantage of the Heroku 'tmp' directory in order to save the file "locally" on staging and production: https://devcenter.heroku.com/articles/read-only-filesystem
Once we save the file in 'tmp', we will iterate through each page of the pdf and save them all separately. We will find the number of PDF pages using the 'pdf-reader' gem.
EDIT:
Here is the custom paperclip processor I wrote to deal with this (all files are pulled down to the tmp directory beforehand):
https://gist.github.com/jessieay/5832466

Ruby: Find non-transparent PNG and convert into JPG

What is the smartest way to find out if a PNG has transparency or not in Ruby? Is it OK if I just check if there's an alpha-channel? If yes: How do I check for an alpha-channel?
I'm writing a script that will convert all PNGs without transparency into smaller JPGs.
Thanks a lot for your help!
UPDATE: In the meantime I've written that script and you can find it at Github.
Checking the alpha channel seems the most sensible thing to do. Is it safe to assume you are using RMagick? did you read the documentation?
>> require 'RMagick'
>> image = Magick::Image.read("a.png").first
>> image.alpha?
=> true
http://www.imagemagick.org/RMagick/doc/image1.html#alpha_q

java ProcessBuilder doesn't work right with Imagemagick on windows

I'm using im4java to call imagemagick from a grails app. The command line I'm trying to get it to use is
convert "c:\ZonesG\web-app\spresources\summarypage_images\00\09\18\myimage.jpg" -resize 100x100 "c:\ZonesG\web-app\spresources\summarypage_images\00\09\18\myimage_thumbnail100.jpg"
or
convert c:\ZonesG\web-app\spresources\summarypage_images\00\09\18\myimage.jpg -resize 100x100 c:\ZonesG\web-app\spresources\summarypage_images\00\09\18\myimage_thumbnail100.jpg
The args passed to ProcessBuilder look correct. There are 5 separate Strings as follows.
convert
c:\ZonesG\web-app\spresources\summarypage_images\00\09\18\myimage.jpg
-resize
100x100
c:\ZonesG\web-app\spresources\summarypage_images\00\09\18\myimage_thumbnail100.jpg
I get an error that the -resize parameter is not valid when I run it through processbuilder. That makes it seem as if it is calling the convert function, but something has happened to the parameters so that it no longer recognizes them. It's not the hypens in the directories. I tried it to different directories and it still doesn't work.
When I run it from the command line it works perfectly.
I've tried adding double quotes around the two file names. Again it works great in the command window but doesn't work from the java code.
Any Ideas?
Thanks for your comment Jonathan,
Meanwhile, I discovered what was happening.
The order of the args mattered more when calling from the ProcessBuilder. I changed it so that the resize and geometry are first and the input image file is next. That made it work.
I had this error too. It is actually because it is running a program from Microsoft in Windows called "convert". To get im4java to run the correct you need to make an environment variable. Eg: IM4JAVA_TOOLPATH=C:\Program Files (x86)\ImageMagick-6.6.4-Q16\

Resources