[Clipart] [Cctools-cchost] function for generating png thumbnails from svg files
jon at creativecommons.org
Wed Nov 7 17:14:17 PST 2007
On Sun, 2007-11-04 at 21:53 -0500, Roan Horning wrote:
> Victor Stone wrote:
> > that's great and we definitely want to include in cchost, however
> > a big caveat because many shared hosting sites disable exec() from
> > script so while technically it's not a generic php solution, enough
> > folks are hungry for it as you've spec'd it.
> I'm trying to keep the code as generic and modular as possible.
> Currently it does heavily rely on the exec() command. I'm using it to
> call inkscape for two things. First is to retrieve the height and
> The second is to generate the desired size png.
> The getid3 svg module will return the height and width of an svg So I
> can easily replace those inkscape calls.
> I see there are two PHP interfaces available for using ImageMagic:
> MagickWand for PHP and IMagick.
> I could use ImageMagic with one of those interfaces to drop the
> function. I initially chose Inkscape because I am familiar with it,
> it is targeted at svg, so I wasn't worried about it's ability to
> a nice thumbnail from whatever svg file it was given.
> Does anyone have any opinions on ImageMagic's handling of svg files?
> there other conversion tools out there with php hooks?
I have not used much for this but it should do fine with getting
generics of a file and for generically converting SVG (as a fallback),
but we will never get as good of quality as with Inkscape because most
of the clip art have been generated with Inkscape on OCAL.
However, I think getting imagemagick/php code working is a higher
priority, because server-side, it will take some convincing to get
inkscape installed and also, Inkscape won't ship with ccHost.
> > There are two things to consider here that I can think of
> > 1) caching YES.
> > You want to watch for cchost events
> > UPLOAD_DONE (to create the thing)
> > UPLOAD_DELETE (to clear the cache)
> > FILE_DONE (to watch for file adds/deletes/replaces)
> Not yet being that familiar with the cchost code, I was thinking of
> adding a check for the existence of a thumbnail in
> pages/places/templates that return html thumbnail code. If it
> exist, then it is created. Of course this could slow to a crawl a
> which calls a number of thumbnails that don't exist.
Crap, the ccHost documentation is offline right now:
Yeah, I think we need the caching method to happen upon upload, and
then, would be great to have a commandline script we could run on the
site, but with some granularity or controls so it doesn't break the
Like for example, there might be some rendering bugs in imagemagick or
inkscape which is needed to run across all thumbnails in the future, so
that type of system would be good...So, it seems like two prongs of
thumbnailing are needed...make sense?
> > remember that an upload record can have multiple images, each with
> > it's own thumbnail. Now you may make an executive decision to only
> > thumbnail the first one and that's totally cool. This is the
> > I came to when doing the flash-mp3 player and playlists: that only
> > 'top' file in the upload record is retrieved when the user requests
> > 'play'
> We could have 128px be the default thumbnail size which gets saved in
> the same directory as the svg file, but give people the option of
> viewing other sizes of thumbnails. These other sizes would go in a
> temporary cache.
That is interesting...the cache/queue for these is super important.
> > 2) keep the actual thumbnail creation code isolated from everything
> > else. This allows for Inkspace dependency to be easily isolated and
> > replaced, but also allows for us to use that smarts in other areas
> > the code (like when a user uploads an avatar that's too big,
> > of rejecting it we should shrink it to the right size)
> So we want a more generic thumbnailer function that handles multiple
> graphic formats? This leans me toward using an ImageMagic interface.
> Or should I break it up into smaller pieces. One function to return
> longer side of a graphic. The thumbnailer function to create it.
> Currently it is called by: svg2thumbnail(<path to svg file>,<size of
> thumbnail as a single number>)
> It creates a png file with the name of the svg suffixed with
> of thumbnail>.png". So svg2thumbnail("/var/www/drawing.svg","128")
> give you a file: /var/www/drawing-tn128.png
> What options would be desirable for this function? It would be easy
> make a passed thumbnail size of "0" default to the full size of the
> So and svg with a width of 270px and height of 290px called as
> svg2thumbnail("drawing1.svg", "0") would give you drawing1.png with a
> size 270px X 290px.
Sounds reasonable...Usually you would want to constrain the vertical
height to the same and let horizontal change...I think best to get some
code up first and then lets look at...Roan, you commit access to ccHost,
If not that, then get it working on test.openclipart.org and then lets
> It could also accept an option that lets one set whether the file
> gets a prefix or suffix which includes the thumbnail size (ie
> tn128-drawing.png or drawing-tn128.png).
> thanks for your input.
Ok, cool...how far have you gotten now ?
I'm lagging on email (as usual)
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> Cctools-cchost mailing list
> Cctools-cchost at lists.sourceforge.net
jon at creativecommons.org
cell: +1.510.499.0894 (80% time)
desk: +1.415.369.8486 (20% time)
Business + Community Manager
Please note: the contents of this email are not intended to be
legal advice nor should they be relied upon as or represented to be
legal advice. Creative Commons cannot and does not give legal advice.
You need to assess the suitability of Creative Commons' tools for
your particular situation, which may include obtaining appropriate
legal advice from a licensed attorney.
More information about the clipart