W
W
winbackgo2014-11-24 13:48:57
PHP
winbackgo, 2014-11-24 13:48:57

How to generate a GIF of a given size from a string?

There is a function that generates a 1x1 px gif. You need to change it so that you can set the size. I can not understand from the specification where to specify the dimensions.

function gifStr($r = 0, $g = 0, $b = 0, $transparent = true) 
{
  return pack('C*',
    71, 73, 70, 56, 57, 97, // "GIF89a"

    // Logical screen descriptor
    1, 0, // logical screen width
    1, 0, // logical screen height
    128, // global color table | color resolution(3) | sort flag | size of global color table (3)
    0, // background color index
    0, // pixel aspect ratio
    $r, $g, $b, 0, 0, 0, // global color table

    // Graphic control extension
    0x21, // extension introducer
    0xF9, // graphic control label
    4, // block size
    1, // disposal method(3) | user input(3) | transparency |
    0, 0, // delay time
    $transparent ? 0 : 1, // transparent color index
    0, // block terminator

    // Image descriptor
    0x2C, // image seperator
    0, 0, // image left position
    0, 0, // image top position
    1, 0, // image height
    1, 0, // image width
    0, // local color | interlaced | ordered | reserved(2) | size of color table (3)

    2, 2, 68, 1, 0, // image data

    59); // gif trailer
}

But you must
function gifStr($width = 1, $height = 1, $r = 0, $g = 0, $b = 0, $transparent = true)  {...}

There is a task to generate 1000 gifs on the fly, 1 pixel gif is generated ~1000 times faster than imagecreate > imagegif (0.00292 sec. vs. 1.75561 sec. imagegif for a thousand gifs)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Plotnikov, 2014-11-24
@ilyaplot

1, 0, // logical screen width
1, 0, // logical screen height

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question