[Commons-l] Fwd: [Wikitech-l] Extension to render Dia as a PNG

Brianna Laugher brianna.laugher at gmail.com
Wed Sep 3 01:45:42 UTC 2008


Maybe someone here knows the answer?
cheers, Brianna


---------- Forwarded message ----------
From: Filipe Brandenburger <lists.filbranden at idilia.com>
Date: 2008/9/3
Subject: [Wikitech-l] Extension to render Dia as a PNG
To: Wikimedia developers <wikitech-l at lists.wikimedia.org>


Hello,

I need an extension to render Dia files as PNGs. I was using this one:
http://www.mediawiki.org/wiki/Extension:Dia

However I saw many problems with it, one of them being the wrong way to
calculate the size of the image.

I tried to fix it, but I did not find a good way to do it.

The extension creates a new class that extends ImageHandler. In
"doTransform" it calls the "dia" binary with special arguments to
convert a .dia file to a .png file. Nothing wrong there.

The problem is that it implements a "getImageSize" method where it
implements a method that reads the XML file to try to "guess" the size
of the image that "dia" will produce in "doTransform", and the problem
is that it guesses wrong.

I think that the best way to do it would be actually to first generate
the PNG image by calling "dia", and then later returning the dimensions
of this PNG by using "getimagesize". The problem is that, as far as I
understood the source code, getImageSize will always be called before
doTransform. In fact, it seems to me that the name of the PNG image that
doTransform receives will start with the width of the image returned by
getImageSize itself.

I implemented a workaround^W^W a dirty hack to fix this issue. In
getImageSize, I am calling "dia" (without the size argument) saving it
to a tmpfile, then using "getimagesize" to get the dimensions of the PNG
in the tmpfile, and then deleting the tmpfile. Then doTransform is
called and it will basically do the same again, call "dia" to create the
image that will be displayed. It works, but it calls "dia" twice, thus
it is twice as slow as it should be.

Is there a way around this? To actually generate the PNG image just once
and calculate its size only once it is generated?

Thanks!
Filipe


_______________________________________________
Wikitech-l mailing list
Wikitech-l at lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l



-- 
They've just been waiting in a mountain for the right moment:
http://modernthings.org/



More information about the Commons-l mailing list