Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » PHP code to resolve PNG transparency issues

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1606 Views
  • gocreative
    Avatar
    Community Member
    17 Posts

    PHP code to resolve PNG transparency issues Link to this post

    I'm working on a website which will primarily be displayed in IE6. The design requires the use of transparent PNG images, and a solution I've used previously is a PHP script. The requirements of the script are as follows:

    1. Before EVERYTHING in the entire site, the following function must be called:

    ob_start();

    2. After EVERYTHING in the entire site, the following must be inserted:

    include_once($_SERVER['DOCUMENT_ROOT']."/mysite/code/png_fix.php");
    echo png_fix(ob_get_clean());

    As you can see, I've placed the PNG fix script at /mysite/code/png_fix.php. The two changes above were inserted into /mysite/code/Page.php (at the beginning and end, obviously).

    This doesn't seem to have any effect. I've used this script on a number of other websites with no problems. Additionally I've tried some JavaScript solutions in the past, with mixed success. The best JavaScript solution I've used (unitpngfix.js) in this case destroys the site layout (elements appear all over the place).

    So, my question is: Have I inserted the PHP-based PNG transparency fix script in the right place?

  • banal
    Avatar
    Community Member
    901 Posts

    Re: PHP code to resolve PNG transparency issues Link to this post

    It seems like your PHP Code is capturing the whole page output and parsing it for PNGs.
    That won't work inside Page.php, since that file holds the model and the controller and is not responsible for output. Your best bet would be to modify the template engine...

    Using a PHP solution for a PNG Fix seems to be rather awkward. It adds a lot of overhead to your page processing and does basically the same as a JavaScript (works on the HTML-Output). If I were implementing a PHP solution (for SilverStripe) I would probably subclass the "Image" class and handle the issue there.

    From my experience there are some very good JS implementations out there.. did you try this one: http://www.dillerdesign.com/experiment/DD_belatedPNG/?

  • gocreative
    Avatar
    Community Member
    17 Posts

    Re: PHP code to resolve PNG transparency issues Link to this post

    That's correct - it needs to capture the entire page's output. I'm not particularly concerned about the overheads/processing as this is an extremely small website that I would estimate will only pull in about 1000 hits per year, tops. This particular script is the only perfect solution I've ever come across - no bugs, no workarounds, and nothing to do except add those three lines of code.

    I haven't tried the JS solution you provided but it seems like a bit of stuffing around to get it working (explicitly specifying elements etc) and I really want to get this site published this week. The client is every designer's worst nightmare lol

    As a SS novice, and definitely not a programmer by any means, how would I go about modifying the template engine as per your suggestion?

  • banal
    Avatar
    Community Member
    901 Posts

    Re: PHP code to resolve PNG transparency issues Link to this post

    Well, this is a really ugly hack and the community here will probably kill me for even posting something like this, but here we go:
    Add your code to the sapphire/main.php file, like you did with Page.php (ob_start(); at the top, rest at the bottom of the file).

    That's it.

    Please note: This code will affect all pages generated by SilverStripe, even the Admin section etc..
    Also: Since you're messing with core files here, you can no longer update your SilverStripe installation easily. You would always have to hack main.php after an update.
    I sincerely hope you find some time to further evaluate the JS solutions ;)

  • gocreative
    Avatar
    Community Member
    17 Posts

    Re: PHP code to resolve PNG transparency issues Link to this post

    Thanks! Unless there are major security issues, I doubt I'll ever upgrade this site (at least in its current form...). Hopefully IE6 is well and truly dead by that point

    1606 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.