Hi,
I sent this message two days ago but I still haven't gotten any answers.
Basically I want to understand how should I use getImageSize() and doTransform() on a subclass of ImageHandler in a way to defer calculation of the image size only after the transformation is done.
On my specific case, I want to use "dia" to convert .dia files to .png, and then use PHP's getimagesize() to get the dimensions of the resulting .png file. The problem is that, from what I saw, doTransform() is called after getImageSize(). Yes, I'm aware of the "Dia" extension, but I found out that it does not handle the image size correctly.
On the code of ImageHandler, there is a comment that suggests that I could return "false" on getImageSize() if I still don't know the size of the image, but I did not understand how to do that and set the appropriate size later.
If any of you could help me with this or point me to the appropriate resources or point me to another mailing list where this subject could be handled I would really appreciate it.
Thanks! Filipe
-----Original Message----- From: "Filipe Brandenburger" lists.filbranden@idilia.com Sent: Tuesday, September 2, 2008 11:22am To: "Wikimedia developers" wikitech-l@lists.wikimedia.org Subject: [Wikitech-l] Extension to render Dia as a PNG
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