46

現在、GD を使用して画像のサイズを変更する際に問題が発生しています。

黒い背景に最初のフレームを配信するアニメーション gif のサイズを変更するまで、すべてが正常に機能します。

私は使用してみましgetimagesizeたが、それは寸法しか与えず、gifとアニメーション化されたものを区別するものは何もありません。

アニメーション GIF の場合、実際のサイズ変更は必要ありません。スキップできるだけで、この目的には十分です。

手がかりはありますか?

PS。imagemagick にアクセスできません。

敬具、

クリス

4

6 に答える 6

18

imagecreatefromgif()関数の PHP マニュアル ページには、必要なコードの短いスニペットがあります。

imagecreatefromgifコメント #59787 by ZeBadger

于 2008-11-11T11:54:59.887 に答える
7

作業関数は次のとおりです。

/**
 * Thanks to ZeBadger for original example, and Davide Gualano for pointing me to it
 * Original at http://it.php.net/manual/en/function.imagecreatefromgif.php#59787
 **/
function is_animated_gif( $filename )
{
    $raw = file_get_contents( $filename );

    $offset = 0;
    $frames = 0;
    while ($frames < 2)
    {
        $where1 = strpos($raw, "\x00\x21\xF9\x04", $offset);
        if ( $where1 === false )
        {
            break;
        }
        else
        {
            $offset = $where1 + 1;
            $where2 = strpos( $raw, "\x00\x2C", $offset );
            if ( $where2 === false )
            {
                break;
            }
            else
            {
                if ( $where1 + 8 == $where2 )
                {
                    $frames ++;
                }
                $offset = $where2 + 1;
            }
        }
    }

    return $frames > 1;
}
于 2008-11-11T12:18:36.923 に答える