<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mustafa Murat Aydın &#187; python</title>
	<atom:link href="http://www.mmaydin.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mmaydin.com</link>
	<description>Bu adam neler yapıyor</description>
	<lastBuildDate>Sun, 31 Jul 2011 12:55:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Php ve python ile hareketli gif süresi hesaplama</title>
		<link>http://www.mmaydin.com/2009/12/php-ve-python-ile-hareketli-gif-suresi-hesaplama/</link>
		<comments>http://www.mmaydin.com/2009/12/php-ve-python-ile-hareketli-gif-suresi-hesaplama/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:28:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programlama]]></category>
		<category><![CDATA[hareketli gif]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[süre hesaplama]]></category>

		<guid isPermaLink="false">http://www.mmaydin.com/?p=12</guid>
		<description><![CDATA[Bir projemde lazım olmuştu hareketli gif süresinin hesaplanması. Sizin de işinize yararsa ne mutlu bana.. php ile function gifSuresiniVer( $dosya ) { /* http://www.w3.org/Graphics/GIF/spec-gif89a.txt burdaki bilgiler dogrultusunda gif in nasil bir yapisi oldugunu anlayabiliriz. */ $gif_grafik_kontrol_regex = "/21f904[0-9a-f]{2}([0-9a-f]{4})[0-9a-f]{2}00/"; $kaynak = file_get_contents($dosya); $icerik = bin2hex($kaynak); /*butun frame sureleri toplanir*/ $toplam_sure = 0; preg_match_all($gif_grafik_kontrol_regex, $icerik, $eslesenler); foreach [...]]]></description>
			<content:encoded><![CDATA[<p>Bir projemde lazım olmuştu hareketli gif süresinin hesaplanması. Sizin de işinize yararsa ne mutlu bana..</p>
<blockquote><p>php ile</p></blockquote>
<pre class="brush: php">

function gifSuresiniVer( $dosya ) {
    /*
    http://www.w3.org/Graphics/GIF/spec-gif89a.txt burdaki bilgiler dogrultusunda
    gif in nasil bir yapisi oldugunu anlayabiliriz.
    */
	$gif_grafik_kontrol_regex = "/21f904[0-9a-f]{2}([0-9a-f]{4})[0-9a-f]{2}00/";
	$kaynak = file_get_contents($dosya);
	$icerik = bin2hex($kaynak);

	/*butun frame sureleri toplanir*/
	$toplam_sure = 0;
	preg_match_all($gif_grafik_kontrol_regex, $icerik, $eslesenler);
	foreach ($eslesenler[1] as $eslesen) {
		//little-endian hex unsigned int'ler decimal'e cevrilir.
		$sure = hexdec(substr($eslesen,-2) . substr($eslesen, 0, 2));
		if ($sure == 0) {
			$sure = 1;
		}
		$toplam_sure += $sure;
	}

    /*
    sureler 100 luk saniyeler olarak saklanir bu yuzden saniyeye ceviriyoruz.
    */
	$toplam_sure /= 100;

	return $toplam_sure;
}

function gifToplamResim( $dosya ) {
    $kaynak = file_get_contents( $dosya );
    $son = 0;
    $adet = 0;
    while ($adet < 100) {
        $nerede = strpos($kaynak, "\x00\x21\xF9\x04", $son);
        if ( $nerede === false ) {
                break;
        } else {
                $son = $nerede + 1;
                $nerede2 = strpos( $kaynak, "\x00\x2C", $son );
                if ( $nerede2 === false ) {
                        break;
                } else {
                        if ( $nerede + 8 == $nerede2 ) {
                                $adet ++;
                        }
                        $son = $nerede2 + 1;
                }
        }
    }

    return $adet;
}

function hareketliGifSureVer( $image_filename ) {
	$frame_sayisi = gifToplamResim($image_filename);
	if ($frame_sayisi == 0) {
		return false;
	}
	$sure = gifSuresiniVer($image_filename);
	return $sure;
}

$dosya = "ornek.gif";
echo hareketliGifSureVer($dosya);
</pre>
<p>test edecekseniz $dosya = "ornek.gif"; ( satır 64) yerine olusturduğunuz php dosyası ile aynı klasorde olan bir hareketli gif adı yazınız.</p>
<blockquote><p>python ile</p></blockquote>
<pre class="brush: python">
#!/usr/bin/python
# -*- coding: utf-8 -*-
from Image import open

dosya = "ornek.gif"
resim = open(dosya)
resim.seek(0)
sure = 0
try:
    while 1:
        sure += resim.info["duration"]
        resim.seek(resim.tell() + 1)
except EOFError:
    pass
print sure
</pre>
<p>test edecekseniz dosya = "ornek.gif" ( satır 5) yerine olusturduğunuz py dosyası ile aynı klasorde olan bir hareketli gif adı yazınız.</p>
<p>Python da bu iş için özel fonksiyonlar olduğu için bana pek bi iş düşmedi <img src='http://www.mmaydin.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mmaydin.com/2009/12/php-ve-python-ile-hareketli-gif-suresi-hesaplama/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

