[Clipart] [Fwd: Tech Icons]

tom whiteley tom.whiteley at gmail.com
Thu Apr 12 08:40:20 PDT 2007


Okay, updated it to remove adobe tags too.

Simple tests seem to work but I don't have adbode Illustrator to test
with for sure.

Cheers,

Tom.

On 4/12/07, Nicu Buculei (OCAL) <nicu at apsro.com> wrote:
> tom whiteley wrote:
> > Python script ok?
> >
> > Usage:
> > python sygbinstrip.py inputfile > outputfile
> >
> > It just removes all <image> type tags from a file and print the result
> > to stdout.
> >
> > I'm not that familar with the internals of svg so hope this is the
> > right way to do it.
> >
> > There is a slight flaw that it removes all newlines as there seems to
> > be a bug in multi-line regex matching my version of python, but the
> > output is still valid svg.
>
> The bulk of the crap inside of an AI-produced SVG start with the tag
> <i:pgf id="adobe_illustrator_pgf"> and end with </i:pgf> and in my
> experience it can be safely deleted.
>
> There are also a few other bits, but those are benign in comparison.
>
> --
> nicu :: http://nicubunu.ro :: http://nicubunu.blogspot.com
> Open Clip Art Library: http://www.openclipart.org
> my cool Fedora wallpapers: http://fedora.nicubunu.ro/wallpapers/
> my clipart collection: http://clipart.nicubunu.ro/
> _______________________________________________
> clipart mailing list
> clipart at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/clipart
>
-------------- next part --------------
#!/usr/bin/python

import re
import sys

#match any opening image tag
image_tag_re_str = r'\<image .*?\>'
image_open_re = re.compile( image_tag_re_str, re.IGNORECASE | re.DOTALL  )

#match any closing image tag, case insensitive
image_close_re = re.compile( r'\<\/image\>', re.IGNORECASE )

#adobe illustrator tags
adobe_regex_str = r'\<i\:pgf id\=\"adobe_illustrator_pgf\"\>.*?\<\/i\:pgf\>'
adobe_regex = re.compile( adobe_regex_str, re.IGNORECASE )

def Strip( text ):
  "Strip text of any image tag's"
  #strip opening image tags
  text = image_open_re.sub( "", text )
  #strip any closing
  text = image_close_re.sub( "", text )
  #strip abobe
  text = adobe_regex.sub( "", text )
  return text
  
def StripFile( svgfile ):
  "Load file and strip image refs, return resulting text"
  contents = open( svgfile, 'r' ).read()
  #flatten
  contents = contents.replace( "\r", "" )
  contents = contents.replace( "\n", "" )
  return Strip( contents )
  
if __name__ == "__main__":  
  if len( sys.argv ) != 2:
    print "Expected svg filename to operate on"
    sys.exit( -1 )
  else:
    file = sys.argv[ 1 ]
    output = StripFile( file )
    print output

  
  


More information about the clipart mailing list