便宜上、動作する C# コードに変換された PHP コードを次に示します。
byte[] byteCode1 = { 0x00, 0x21, 0xF9, 0x04 };
byte[] byteCode2 = { 0x00, 0x2C };
String strTemp;
byte[] byteContents;
bool bIsAnimatedGif = false;
int iCount;
int iPos = 0;
int iPos1;
int iPos2;
Stream st = null;
// st is a stream previously opened on a file
byteContents = new byte[st.Length];
st.Read(byteContents, 0, (int)st.Length);
strTemp = System.Text.Encoding.ASCII.GetString(byteContents);
byteContents = null;
iCount = 0;
while (iCount < 2)
{
iPos1 = strTemp.IndexOf(System.Text.Encoding.ASCII.GetString(byteCode1), iPos);
if (iPos1 == -1) break;
iPos = iPos1 + 1;
iPos2 = strTemp.IndexOf(System.Text.Encoding.ASCII.GetString(byteCode2), iPos);
if (iPos2 == -1) break;
if ((iPos1 + 8) == iPos2)
iCount++;
iPos = iPos2 + 1;
}
if (iCount > 1) bIsAnimatedGif = true;