[pmwiki-users] Request: Transparent PNGs in PmWiki
Joachim Durchholz
jo at durchholz.org
Sat Mar 18 03:05:42 CST 2006
Hans schrieb:
> Friday, March 17, 2006, 7:26:29 AM, Allister wrote:
>> Cheers. That looks like it is using similar stuff.
>
> http://pmwiki.org/wiki/Test/Opacity is not using the method described
> on http://www.willhowat.com/knowledge/transparent_png.aspx, but both IE's
> and Mozilla's built in opacity style attributes.
Note that it didn't work for me on IE - despite running on a Win 2000
Pro that's been doing it regular updates, and with JS switched on.
So whatever that page is doing, it's still too fragile to work well.
I have yet to see an IE hack that works well enough for productive use.
An alternative would be the technique employed on http://itsy.de. The
URL of the logo in the top-left corner is
http://itsy.de/hg.php?F9F9FB-/images/itsy-100x60.png
hg.php is a q&d script that takes the query string, splits it into a
background color and an image URL, renders the PNG on a background of
that color, and streams out the result.
Find the code for hg.php below. It's a standalone script, so it can be
used with PmWiki or any other site.
It has room for improvements, e.g. cache the rendered results, and I'm
not too sure about query string syntax, but it has been doing its job
well at itsy.de :-)
Using an arbitrary background image would be a straightforward
extension, I just had no use for that yet.
Enjoy!
Jo
--- snip ---
<?php
# hg.php
# Copyright (C) 2006 Joachim Durchholz
# This work is licensed under the GPL 2.0,
# see http://creativecommons.org/licenses/GPL/2.0/
# for the license text.
function not_found () {
header ('Status: 404 Not Found');
require ('fehler404.html');
die;
}
if (!
preg_match (
'/\?([0-9a-f]{6})-([^?]*.png)$/i',
$_SERVER ['REQUEST_URI'],
$matches
)
) {
not_found ();
}
if (count ($matches) != 3) not_found ();
$background_color = $matches [1];
$filename = $matches [2];
if ($filename [0] == '/') $filename = '.' . $filename;
if (! $in_image = imagecreatefrompng ($filename)) not_found;
$width = imagesx ($in_image);
$height = imagesy ($in_image);
$out_image = imagecreatetruecolor ($width, $height);
sscanf ($background_color, '%02x%02x%02x', $r, $g, $b);
$background_color = imagecolorallocate ($out_image, $r, $g, $b);
imagefilledrectangle
($out_image, 0, 0, $width - 1, $height - 1, $background_color);
imagecopy (
$out_image, $in_image,
0, 0, 0, 0, # x/y of out_image and in_image
$width, $height
);
header ('Content-type: image/png');
imagepng ($out_image);
--- snip ---
More information about the pmwiki-users
mailing list