Modify

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#8812 closed defect (fixed)

Images of formulas look shoddy when opened with gimp

Reported by: heber@… Owned by: Kamil Kisiel
Priority: normal Component: TracMathPlugin
Severity: normal Keywords: png images, pixelated, black pixels
Cc: Trac Release: 0.11

Description

TracMathplugin (here 0.3) generates the formulas as tiny .png images embedded into the html page. These images look decent when viewed with browsers such as firefox (here 3.6.17). However, if one downloads the image and opens it up in image manipulator such as gimp, the image looks very grainy/pixelated. Only truely black pixel are visible, everything gray is lost (made transparent).

The problem can be remedied within gimp if the color palette (in the gimp menu, that's Image/Mode) is changed from indexed to rgb. Then suddenly gray pixels become visible.

I don't know how the pngs are rendered, so I am not much of a help here but hopefully the palette thing gives a clue to this.

Attachments (0)

Change History (6)

comment:1 Changed 13 years ago by heber@…

As a sidenote: I came upon this issue because I am using TracWikiPrintPlugin to generate PDFs from the TRAC pages as a sort layman's way to generate simple and pretty latex pages (we use it here for quickly generating sheets for a molecular dynamics tutorial). However, the formulas looked just plain ugly in the PDF while absolutely acceptable on the TRAC page.

comment:2 Changed 13 years ago by Kamil Kisiel

Status: newassigned

This probably has to do with the png compression. It seems the plugin is using maximum compression for PNGs in order to save space. I can make a version where the compression level is configurable and you can see if setting it to a lower value helps.

comment:3 Changed 13 years ago by Kamil Kisiel

Please try version 0.4 of the plugin, it includes a compression option in the [tracmath] section of the config file. You can set the option to a number from 1 - 9, where 1 is lower and 9 is higher. Let me know if it makes any difference.

comment:4 Changed 13 years ago by heber@…

Resolution: fixed
Status: assignedclosed

That does the trick, although I do not see any change in size of the images representing formulas when changing compression from 1 to 9.

There is one more thing: the formulas might become larger than desired on the webpage compared to a generated PDF (via TracWikiPrintPlugin). We patched your plugin as follows:

der patch:
--- tracmath/tracmath.py	2010-12-21 20:59:02.000000000 +0100
+++ tracmath/tracmath.py	2011-05-24 15:07:42.000000000 +0200
@@ -16,6 +16,7 @@
 from trac.web import IRequestHandler
 from trac.util import escape
 from trac import mimeview
+import Image

 __author__ = 'Reza Lotun'
 __author_email__ = 'rlotun@gmail.com'
@@ -170,8 +171,10 @@
             # Touch the file to keep it live in the cache
             os.utime(imgpath, None)

-        result = '<img src="%s/tracmath/%s" alt="%s" />' %
(req.base_url, imgname, content)
-        if label:
+	im=Image.open(imgpath)
+	height=im.size[1]
+	result = '<img src="%s/tracmath/%s" alt="%s" height="%spx"
class="formula"/>' % (req.base_url, imgname, content, int(height *(1/
(self.mag_factor/1200.0) *1.2) ))
+	if label:
             result = '<a name="%s">(%s)<a/>&nbsp;%s' % (label, label,
result)
         return result

@@ -200,7 +203,9 @@
         latex = '/usr/bin/latex'
         dvipng = '/usr/bin/dvipng'
         max_png = 500
-        mag_factor = 1200
+        #mag_factor = 1200
+	#see dvipng manpage -x for valid values
+        mag_factor = 2488

         if 'tracmath' not in self.config.sections():
             pass    # TODO: do something

That is we changed the variable mag_factor to adapt the size of the formulas to the size of rest of the text.

comment:5 Changed 13 years ago by Kamil Kisiel

Glad to hear it worked for you, and thanks for the suggestion. I don't want to introduce a dependency on the Python Imaging Library so I think I'll leave it in your hands for now.

I should note that you can change the mag_factor option in trac.ini

comment:6 Changed 13 years ago by heber@…

Thanks for looking into this bug and thanks for the great plugin!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Kamil Kisiel.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.