Ciao a tutti, ho da poco trovato questo piccolo script, su un sito, che permette, tramite php, di creare gif animate al volo. Dopo averlo provato devo dire che funziona, ma purtroppo non riesco a modificarlo per fare in modo che utilizzi immagini al posto di colori . Mi devo rimettere di nuovo al vostro aiuto.

Script normale:
Codice PHP:
<?
header
('Content-Type: image/gif');
header('Cache-control: no-cache, no-store');

function 
get_gif_header($gif_data) {
$header = array();
$header["signature"] = substr($gif_data,0,3);
$header["version"] = substr($gif_data,3,3);
$header["logical_screen_width"] = substr($gif_data,6,2);
$header["logical_screen_height"] = substr($gif_data,8,2);
$header["packed"] = substr($gif_data,10,1);
$header["background_color_index"] = substr($gif_data,11,1);
$header["pixel_aspect_ratio"] = substr($gif_data,12,1);
$packed ord($header["packed"]);
if ((
$packed >> 7) & 0x1) {
$gct $packed 3;
$gct_size pow(2,$gct+1);
$header["global_color_table"] = substr($gif_data,13,$gct_size);
}
return 
$header;
}

function 
strip_gif_header($gif_data) {
$without_header "";
$header_len 0;
$header get_gif_header($gif_data);
foreach (
$header as $k=>$v)
$header_len += strlen($v);
return 
substr($gif_data,$header_len,strlen($gif_data)-$header_len);
}

function 
get_gif_image_data($gif_data) {
$no_header strip_gif_header($gif_data);
$no_header substr($no_header,0,strlen($no_header)-1);
return 
$no_header;
}

function 
get_gif_image_descriptor($image_data) {
$header = array();
$header["image_separator"] = substr($image_data,0,1);
$header["image_left_position"] = substr($image_data,1,2);
$header["image_top_position"] = substr($image_data,3,2);
$header["image_width"] = substr($image_data,5,2);
$header["image_height"] = substr($image_data,7,2);
$header["packed"] = substr($image_data,9,1);
$packed ord($header["packed"]);
if ((
$packed >> 7) & 0x1) {
$lct $packed 3;
$lct_size pow(2,$lct+1);
$header["local_color_table"] = substr($image_data,10,$lct_size);
}
return 
$header;
}

function 
strip_gif_image_descriptor($imgdata) {
$descriptor get_gif_image_descriptor($imgdata);
$len 0;
foreach (
$descriptor as $k=>$v)
$len += strlen($v);
return 
substr($imgdata,$len,strlen($imgdata)-$len);
}

function 
make_gifanim($gifs) {
$head0 get_gif_header($gifs[0]);
$head0["packed"] = chrord($head0["packed"]) & (<< 4) );
$head0["background_color_index"] = chr(0);
$head0["pixel_aspect_ratio"] = chr(0);
unset(
$head0["global_color_table"]);
$anim_gif implode("",$head0);
$extra_info = array( chr(0x21), chr(0xff) ,chr(0x0B), "NETSCAPE2.0",chr(0x03), chr(0x01), chr(0x00).chr(0x00), chr(0x00) );
$anim_gif .= implode("",$extra_info);
foreach (
$gifs as $gif) {
$header get_gif_header($gif);
$imgdata get_gif_image_data($gif);
$image_header get_gif_image_descriptor($imgdata);
$image_only strip_gif_image_descriptor($imgdata);
$control_block = array();
$control_block["extension_introducer"] = chr(0x21);
$control_block["graphic_control_label"] = chr(0xF9);
$control_block["block_size"] = chr(4);
$control_block["packed"] = chr(0);
$control_block["delay"] = chr(50).chr(0);
$control_block["transparent_color_index"] = chr(0);
$control_block["terminator"] = chr(0);
if (!isset(
$image_header["local_color_table"]) && isset($header["global_color_table"])) {
$image_header["local_color_table"] = $header["global_color_table"];
$size_gct = (ord($header["packed"]) & 3);
$image_header["packed"] = chrord($image_header["packed"]) | (0x1 << 7) | ($size_gct) );
}
$anim_gif .= implode("",$control_block).implode("",$image_header).$image_only;
}
$anim_gif .= chr(0);
return 
$anim_gif;
}

$tot_frames 30;
$anim_len 10;
$start_dummy rand(0,10);
$end_dummy rand($start_dummy+$anim_len,30);
$max_h 50;
$max_l 350;
$delay 50;
$files = array();


for (
$f=0;$f<$tot_frames;$f++) {
$im = @imagecreatetruecolor($max_l$max_h)
or die(
"Cannot Initialize new GD image stream");
if (
$new_code == "")
$new_code "P R O V A 1 2 3";
$background_color imagecolorallocate($imrand(0,255), rand(0,255), rand(0,255));
$tot_rects rand(1,5);
$rl intval($max_l $tot_rects);
for (
$r=0;$r<$tot_rects;$r++) {
$rect_color imagecolorallocate($imrand(0,255), rand(0,255), rand(0,255));
$rx = ($rl*$r);
imagefilledrectangle($im,$rx,0,$rx+$rl,$max_h,$rect_color);
}
$cur_x 0;
if (
$f>$start_dummy && $f<$end_dummy)
for (
$i=0;$i<strlen($new_code);$i++) {
$font rand(3,5);
$y rand(0,$max_h imagefontheight($font));
do {
$text_color imagecolorallocate($imrand(0,255), rand(0,255), rand(0,255));
} while (
$background_color == $text_color);
imagestring($im$font $cur_x$y$new_code{$i}, $text_color);
$cur_x += imagefontwidth($font)+3;
}
ob_start();
imagegif($im);
$files[] = ob_get_clean();
imagedestroy($im);
}

echo 
make_gifanim($files);
?>
Script con la modifica che ho provato a fare:
Codice PHP:
<?
header
('Content-Type: image/gif');
header('Cache-control: no-cache, no-store');

function 
get_gif_header($gif_data) {
$header = array();
$header["signature"] = substr($gif_data,0,3);
$header["version"] = substr($gif_data,3,3);
$header["logical_screen_width"] = substr($gif_data,6,2);
$header["logical_screen_height"] = substr($gif_data,8,2);
$header["packed"] = substr($gif_data,10,1);
$header["background_color_index"] = substr($gif_data,11,1);
$header["pixel_aspect_ratio"] = substr($gif_data,12,1);
$packed ord($header["packed"]);
if ((
$packed >> 7) & 0x1) {
$gct $packed 3;
$gct_size pow(2,$gct+1);
$header["global_color_table"] = substr($gif_data,13,$gct_size);
}
return 
$header;
}

function 
strip_gif_header($gif_data) {
$without_header "";
$header_len 0;
$header get_gif_header($gif_data);
foreach (
$header as $k=>$v)
$header_len += strlen($v);
return 
substr($gif_data,$header_len,strlen($gif_data)-$header_len);
}

function 
get_gif_image_data($gif_data) {
$no_header strip_gif_header($gif_data);
$no_header substr($no_header,0,strlen($no_header)-1);
return 
$no_header;
}

function 
get_gif_image_descriptor($image_data) {
$header = array();
$header["image_separator"] = substr($image_data,0,1);
$header["image_left_position"] = substr($image_data,1,2);
$header["image_top_position"] = substr($image_data,3,2);
$header["image_width"] = substr($image_data,5,2);
$header["image_height"] = substr($image_data,7,2);
$header["packed"] = substr($image_data,9,1);
$packed ord($header["packed"]);
if ((
$packed >> 7) & 0x1) {
$lct $packed 3;
$lct_size pow(2,$lct+1);
$header["local_color_table"] = substr($image_data,10,$lct_size);
}
return 
$header;
}

function 
strip_gif_image_descriptor($imgdata) {
$descriptor get_gif_image_descriptor($imgdata);
$len 0;
foreach (
$descriptor as $k=>$v)
$len += strlen($v);
return 
substr($imgdata,$len,strlen($imgdata)-$len);
}

function 
make_gifanim($gifs) {
$head0 get_gif_header($gifs[0]);
$head0["packed"] = chrord($head0["packed"]) & (<< 4) );
$head0["background_color_index"] = chr(0);
$head0["pixel_aspect_ratio"] = chr(0);
unset(
$head0["global_color_table"]);
$anim_gif implode("",$head0);
$extra_info = array( chr(0x21), chr(0xff) ,chr(0x0B), "NETSCAPE2.0",chr(0x03), chr(0x01), chr(0x00).chr(0x00), chr(0x00) );
$anim_gif .= implode("",$extra_info);
foreach (
$gifs as $gif) {
$header get_gif_header($gif);
$imgdata get_gif_image_data($gif);
$image_header get_gif_image_descriptor($imgdata);
$image_only strip_gif_image_descriptor($imgdata);
$control_block = array();
$control_block["extension_introducer"] = chr(0x21);
$control_block["graphic_control_label"] = chr(0xF9);
$control_block["block_size"] = chr(4);
$control_block["packed"] = chr(0);
$control_block["delay"] = chr(50).chr(0);
$control_block["transparent_color_index"] = chr(0);
$control_block["terminator"] = chr(0);
if (!isset(
$image_header["local_color_table"]) && isset($header["global_color_table"])) {
$image_header["local_color_table"] = $header["global_color_table"];
$size_gct = (ord($header["packed"]) & 3);
$image_header["packed"] = chrord($image_header["packed"]) | (0x1 << 7) | ($size_gct) );
}
$anim_gif .= implode("",$control_block).implode("",$image_header).$image_only;
}
$anim_gif .= chr(0);
return 
$anim_gif;
}

$tot_frames 30;
$anim_len 10;
$start_dummy rand(0,10);
$end_dummy rand($start_dummy+$anim_len,30);
$max_h 20;
$max_l 400;
$delay 50;
$files = array();


for (
$f=0;$f<$tot_frames;$f++) {
//$im = @imagecreatetruecolor($max_l, $max_h);
$imgname="ban001.gif";
$im = @imagecreatefromgif($imgname);
if (!
$im) { /* See if it failed */
        
$im  imagecreatetruecolor(15030); /* Create a blank image */
        
$bgc imagecolorallocate($im255255255);
        
$tc  imagecolorallocate($im000);
        
imagefilledrectangle($im0015030$bgc);
        
/* Output an errmsg */
        
imagestring($im155"Error loading $imgname"$tc);
    }
/*
if ($new_code == "")
$new_code = "P R O V A 1 2 3";
$background_color = imagecolorallocate($im, rand(0,25.$f), rand(0,255), rand(0,255));
$tot_rects = rand(1,5);
$rl = intval($max_l / $tot_rects);
for ($r=0;$r<$tot_rects;$r++) {
$rect_color = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
$rx = ($rl*$r);
imagefilledrectangle($im,$rx,0,$rx+$rl,$max_h,$rect_color);
}
$cur_x = 0;
if ($f>$start_dummy && $f<$end_dummy)
for ($i=0;$i<strlen($new_code);$i++) {
$font = rand(3,5);
$y = rand(0,$max_h - imagefontheight($font));
do {
$text_color = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
} while ($background_color == $text_color);
imagestring($im, $font , $cur_x, $y, $new_code{$i}, $text_color);
$cur_x += imagefontwidth($font)+3;
}
*/
ob_start();
imagegif($im);
$files[] = ob_get_clean();
imagedestroy($im);
}

echo 
make_gifanim($files);
?>
(per ora ho provato a caricare semplicemente una img per vedere il risultato ma mi rimane la pagina bianca...)

Spero che voi riusciate a risolverequesto piccolo problema
grazie a tutti in anticipo ^^