Greg Donald wrote:
Murray wasn't asking for your opinions on _his_ code, he was asking
what code _you_ had that you couldn't live without, code that makes
your life easier when reused from project to project.

Ok then. Here comes mine (but not in form of source code. If someone is interested, mail me).

I'm doing a lot with dynamic image generation and so I've written a gdutils include file containing the following:


imagecolorallocatehex($image, $color) - Allocate a color for an image from hexadecimal value. Useful to have the same color syntax for HTML and GD output.

imagecolorallocatehexalpha($image, $color, $alpha) - Pretty the same as the first function but this time for alpha transparent colors.

imagecreatefromfile($filename) - Checks the image format with getimagesize() and loads the image with one of the imagecreatefrom(gif|jpeg|png|bmp|xbm) functions.

img_type_to_extension($imgtype, $include_dot = false) - Returns the extension for the given image type.

imagettfbbox2($size, $angle, $fontfile, $text, $fix_vertical = false) - An improved version of imagettfbbox. Returns "correct" data (even if text is rotated) and also returns "more useful" data (associative array with keys left, right, top, bottom, width and height.

imagecopyresampled2($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH) - A workaround for the buggy imagecopyresampled. The GD library can't really resample images with alphatransparency (see bug #29315). So my function passes the GD image to ImageMagick/GraphicsMagick (with the imagick module from PECL) which resamples the image and passes it back to GD.


And two more functions I'm using regularly:

mkpath($path, $mode) - Create a directory with all parent directories and make sure the directory mode is really set (setting umask to 0 during directory creation)

redirect($url) - Creates a correct url (absolute and with SID if needed), sends location header and exits the script.

--
Bye, K <http://www.ailis.de/~k/> (FidoNet: 2:240/2188.18)
[A735 47EC D87B 1F15 C1E9  53D3 AA03 6173 A723 E391]
(Finger [EMAIL PROTECTED] to get public key)

Attachment: signature.asc
Description: OpenPGP digital signature



Reply via email to