Help with PNG creation script

From: Ashley M. Kirchner (ashley_at_pcraft.com)
Date: 12/31/03


Date: Wed, 31 Dec 2003 03:04:13 -0700
To: php-general@lists.php.net



    The attached text file contains a script that I've gotten from a web
site and that I've been using for a while now to generate on the fly PNG
headers. There can be several headers on one page, spanning several
days worth of articles. The script works, except it's a huge overhead
because it generates each header every time it gets displayed. What I'd
like to do is amend the script to where it will creates a physical PNG
file on the server, so that the next time it's called, it will check its
"cache" first to see if that particular header already exists before
creating another. Basically something to the tune of:

    a web page calls the script:

    script checks internal cache for that header
      if header doesn't exist
        create header -> save in cache (disk based?)
      endif
      serve header from cache
    end routine

    I don't know if it makes sense to incorporate this with an MySQL
database which contains pointers to the physical files on disk. I don't
know if that will speed up the searching for a particular header
(searching the DB, as opposed to scanning the disk directory.) The only
thing I can think of is to have a database with a table that contains
both article dates as well as the pointer, so the search only has to go
through a small set of records, as opposed to the whole DB, but is it
really worth it?

    Now, somewhere in there, it also needs to scan the cache for old
headers that are no longer needed, based on a time frame that I set
(maybe 14 days? maybe 30 days? I haven't decided yet.) Again, maybe
using a DB is worth it so one can simply delete all the pointers and
physical files confirming to a specific range search in the DB? Right
now, I just want the thing to cut down on CPU usage because it's
generating those headers every time a page gets called. Not good.
     

-- 
W | I haven't lost my mind; it's backed up on tape somewhere.
  +--------------------------------------------------------------------
  Ashley M. Kirchner <mailto:ashley@pcraft.com>   .   303.442.6410 x130
  IT Director / SysAdmin / WebSmith             .     800.441.3873 x130
  Photo Craft Laboratories, Inc.            .     3550 Arapahoe Ave. #6
  http://www.pcraft.com ..... .  .    .       Boulder, CO 80303, U.S.A.

<?php
  function label($text) {
    $georgia = $_SERVER["DOCUMENT_ROOT"]."/fonts/georgiaz.ttf";
    $freeformi = $_SERVER["DOCUMENT_ROOT"]."/fonts/tt1002m_.ttf";
    $fontsize = 11;
    $pad = 30;
    $image = imagecreate(1000,25);
    $background = ImageColorAllocate($image, 115,180,200);
    $bcolor1 = ImageColorAllocate($image, 125,190,210);
    $bcolor2 = ImageColorAllocate($image, 105,160,180);
    $bcolor3 = ImageColorAllocate($image, 105,170,190);
    $color = ImageColorAllocate($image, 0,17,85);
    ImageRectangle($image,0,0,1000,25,$background);
    ImageTTFText($image, 30, 0, 49, 29, $bcolor1, $freeformi, strtoupper($text));
    ImageTTFText($image, 30, 0, 53, 33, $bcolor2, $freeformi, strtoupper($text));
    ImageTTFText($image, 30, 0, 51, 31, $bcolor3, $freeformi, strtoupper($text));
    ImageTTFText($image, $fontsize, 0, (int)($pad/2), 18, $color, $georgia, "::: ".stripslashes($text));
    return($image);
  }
  Header("Content-type: image/png");
  ImagePNG(label($text));
  ImageDestroy($image);
?>



Relevant Pages

  • Re: IXSSO - not generating/returning Characterization or DocTitle
    ... After adding these headers, I initiated a "full rescan" of the ... directory that contains this document via the IS MMC. ... I have tried searching on the three keywords contained in the header. ... >> Dim util As New CissoUtilClass ...
    (microsoft.public.inetserver.indexserver)
  • Re: Searching email headers
    ... Post ot a programming group for a better answer. ... However, since the vast majority of the headers are spoofed, you will most ... After searching google.groups.com and finding no answer, Dan Frederick ...
    (microsoft.public.outlook)
  • Re: Finding a string in a file
    ... Debbie Cooper wrote on 25.05.2004: ... The file I'm searching ... >headers and I need to search the header for a specific word like ...
    (perl.beginners)
  • Re: MimeOLE V6.00.2900.2180 creates incorrect X- header
    ... I don't know that there is an RFC that dictates the format of the end of a header. ... The OE client IS searching the SUBJECT header for the string ... based on some other line in the headers using a message rule will not work. ... > correctly applies a 'local' mail rule - ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Ping Andrew
    ... Searching for 'harvest', including headers and part-words, returns nowt NAAW. ...
    (uk.rec.sheds)