images - Convert .ai to .png?

08
2013-08
  • pimvdb

    I just downloaded a free vector graphics set which contained UI elements and icons. The button graphics have some text on them. It were, however, .ai files which are not familiar to me.

    Obviously, I did a search on Google. It turned out that:

    • you can open .ai files with Adobe Reader. Great, I could take a screenshot from there, but I cannot remove the texts on the graphics as I'm using Reader...
    • you can import it in GIMP but then the text and graphics are blent together which means I cannot remove the text either.

    Is there a way to easily convert .ai to .png without too much clutter and so that the text isn't put on the images? I only need the background of the buttons, i.e. not the text like 'Test' which is just put on it to show how it looks with text.

    Thanks.

  • Answers
  • Daniel Beck

    You can use ai2svg.py to convert the ai file to svg, then open and edit the result in Inkscape.


    Inkscape might be able to open the files directly as well, but you might need additional software.


  • Related Question

    Batch converting PNG to JPG in linux
  • humble coffee

    Does anyone know a good way to batch-convert a bunch of PNGs into JPGs in linux? (I'm using Ubuntu).

    A png2jpg binary that I could just drop into a shell script would be ideal.


  • Related Answers
  • evilsoup

    Your best bet would be to use Imagemagick

    I am not an expert in the actual usage, but I know you can pretty much do anything image related with this!

    An example is:

    convert image.png image.jpg
    

    and it will keep the original as well as creating the converted image. As for batch. I think you need to use the Mogrify tool (from the same command line when in imagemagick). Keep in mind that this overwrites the old images.

    The command is:

    mogrify -format jpg *.png  
    
  • Matt Ryall

    The convert command found on many Linux distributions is installed as part of the ImageMagick suite. Here's the bash code to run convert on all PNG files in a directory and avoid that double extension problem:

    for img in *.png; do
        filename=${img%.*}
        convert "$filename.png" "$filename.jpg"
    done
    
  • Teddy

    The actual "png2jpg" command you are looking for is in reality split into two commands called pngtopnm and cjpeg, and they are part of the netpbm and libjpeg-progs packages, respectively.

    png2pnm foo.png | cjpeg > foo.jpeg
    
  • evilsoup

    I have a couple more solutions.

    The simplest solution is like most already posted. A simple bash for loop.

    for i in *.png ; do convert "$i" "${i%.*}.jpg" ; done
    

    For some reason I tend to avoid loops in bash so here is a more unixy xargs approach, using bash for the name-mangling.

    ls -1 *.png | xargs -n 1 bash -c 'echo "$0" "${0%.*}.jpg"'
    

    The one I use. It uses GNU Parallel to run multiple jobs at once, giving you a performance boost. It is installed by default on many systems and is almost definitely in your repo (it is a good program to have around).

    parallel convert '{}' '{.}.jpg' ::: *.png
    

    The number of jobs defaults to the number of processes you have. I found better CPU usage using 3 jobs on my dual-core system.

    parallel -j 3 convert '{}' '{.}.jpg' ::: *.png
    

    And if you want some stats (an ETA, jobs completed, average time per job...)

    parallel --eta convert '{}' '{.}.jpg' ::: *.png
    

    The final command that I use looks like this for refrence. I use ls rather than parallel's syntax for who-knows-what reason.

    ls -1 *.png | parallel -j 3 --eta convert '{}' '{.}.jpg'
    
  • Jeffrey Aylesworth

    For batch processing:

    for img in *.png; do
      convert "$img" "$img.jpg"
    done
    

    You will end up with file names like image1.png.jpg though.

    This will work in bash, and maybe bourne. I don't know about other shells, but the only difference would likely be the loop syntax.

  • max

    my quick solution for i in $(ls | grep .png); do convert $i $(echo $i.jpg | sed s/.png//g); done