<?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>Sniper &#187; otomatik thumbnail</title>
	<atom:link href="http://tuncay.kinali.net/etiketler/otomatik-thumbnail/feed" rel="self" type="application/rss+xml" />
	<link>http://tuncay.kinali.net</link>
	<description>Hafızamın bir kısmı</description>
	<lastBuildDate>Sun, 01 Aug 2010 09:49:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP ile otomatik thumbnail oluşturun</title>
		<link>http://tuncay.kinali.net/php-ile-otomatik-thumbnail-olusturun.html</link>
		<comments>http://tuncay.kinali.net/php-ile-otomatik-thumbnail-olusturun.html#comments</comments>
		<pubDate>Thu, 27 Aug 2009 18:33:10 +0000</pubDate>
		<dc:creator>Sniper</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[otomatik thumbnail]]></category>

		<guid isPermaLink="false">http://tuncay.kinali.net/?p=183</guid>
		<description><![CDATA[Bugüne kadar hazırladığım web siteleri çoğunlukla katalog tarzı ürün tanıtım siteleriydi. Bu sitelerde bir ürünün farklı ebatlarda resimlerini sitenin çeşitli yerlerinde kullanmam gerekiyordu. Zamanında buna çare olarak bir script hazırlamıştım. Script, kendisine parametre olarak gönderilen resmin istenilen boyutlarda bir küçük kopyasını çalışma anında oluşturuyor ve tarayıcıya gönderiyordu. Böylelikle hem disk alanından kâr ediyor, hem de [...]]]></description>
			<content:encoded><![CDATA[<p>Bugüne kadar hazırladığım web siteleri çoğunlukla katalog tarzı ürün tanıtım siteleriydi. Bu sitelerde bir ürünün farklı ebatlarda resimlerini sitenin çeşitli yerlerinde kullanmam gerekiyordu. Zamanında buna çare olarak bir script hazırlamıştım. Script, kendisine parametre olarak gönderilen resmin istenilen boyutlarda bir küçük kopyasını çalışma anında oluşturuyor ve tarayıcıya gönderiyordu. Böylelikle hem disk alanından kâr ediyor, hem de her boyut için manuel olarak tüm resimlerin thumbnailini oluşturma zahmetinden kurtuluyordum. <span id="more-183"></span></p>
<p>Bu scripti, ASP yazdığım zamanlarda ASPJpeg bileşeni kullanarak geliştirmiştim. PHP&#8217;ye geçince aynı işi yapan PHP kodlarını da hazırladım ama bu kodlar ASP&#8217;deki kadar hızlı çalışmıyordu. Resimlerin görüntülenmesinde gözle görülür bir yavaşlama söz konusuydu ama gerek zamansızlık, gerekse PHP alanında tecrübesiz olmamdan dolayı bu konunun üstünde fazla durmamıştım. Son birkaç gündür bu scriptle ilgilenme fırsatım oldu ve nasıl daha az kaynak tüketerek scripti daha verimli hale getirebilirim diye düşündüm. Madem her resmin thumbnail&#8217;i oluşturulup tarayıcıya gönderiliyor, neden bunları bir dosyaya kaydetmeyeyim? Hem bir sonraki çağırılışlarında direkt oluşturduğum dosyayı çağırırım ve işlemciyi yormam, hem de her resmin istediğim ebatlardaki thumbnaillerini elimi sürmeden oluşturmuş olurum.</p>
<p>Scriptin adı thumb.php, dışarıdan 3 parametre alıyor:</p>
<ul>
<li><strong>p:</strong> Üzerinde işlem yapılacak olan resmin dosya sistemi üzerindeki tam yolu. Scriptin esprisini kaybetmemesi açısından yeniden boyutlandırılacak resmin bulunduğu klasörün yazma izinleri ayarlanmış olmalıdır.</li>
<li><strong>w:</strong> Resmin dönüştürüleceği maximum genişlik. (Kötü amaçlı kullanımlardan korunmak amacıyla 1024px ile sınırlandırılmıştır.)</li>
<li><strong>h:</strong> Resmin dönüştürüleceği maximum yükseklik. (Kötü amaçlı kullanımlardan korunmak amacıyla 768px ile sınırlandırılmıştır.)</li>
</ul>
<p><strong>w</strong> ve <strong>h</strong> parametreleri opsiyonel olup istenirse her ikisinin de kullanılacağı gibi sadece biri de kullanılabilir. Hiçbirini kullanmamak resmi doğrudan çağırmakla eşdeğer olacağından bir anlam ifade etmez. Scriptin çalışma mantığı özetle şöyle:</p>
<ul>
<li>Resmin genişlik ve yükseklik parametreleri alınır, yukarıda bahsedilen sınırlandırma uygulanır.</li>
<li>p parametresinde belirtilen resim dosyasının varlığı doğrulanır.</li>
<li>Resim için bir thumbnail dosya adı oluşturulur. Bu dosya adı; orjinal resmin adı[_<strong>w</strong>[genişlik değeri_<strong>h</strong>yükseklik değeri]].uzantı formatındadır. (Örneğin: &#8220;thumb.php?p=sniper.jpg&#038;w=100&#038;h=75&#8243; olarak çağırılan dosyanın thumbnail adı &#8220;sniper_w100_h75.jpg&#8221; olacaktır.)</li>
<li>Ortaya çıkan thumbnail dosya adı kullanılarak daha önce bu isimde bir dosya oluşturulmuşsa script o dosyaya yönlenir ve çalışmayı durdurur.</li>
<li>Resim dosyası belirtilen özelliklerle ilk defa çağırılıyorsa istenilen genişlik ve yükseklik değerleri işlenip orantılı bir şekilde küçük resim oluşturulur.</li>
<li>Resmin bulunduğu klasörün yazma izinleri ayarlanmışsa oluşturulan küçük resim klasöre kaydedilir, script kaydedilen dosyaya yönlendirilir ve çalışmayı durdurur.</li>
<li>Eğer klasörün yazma izni yoksa oluşturulan thumbnail direkt olarak tarayıcıya gönderilir ve dosyanın sonraki çağırılışlarında tüm bu işlemler tekrar eder.</li>
</ul>
<p>Son olarak birkaç örnek kullanım ve bu kullanımlar sonucunda oluşacak dosya bilgilerini verdikten sonra kodları alabilirsiniz. Örnek kodlar 1280&#215;960 px boyutlarında bir resim üzerinde çalıştırılmıştır.</p>
<div style="overflow:auto; margin-bottom:8px;">

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p183code5'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1835"><td class="code" id="p183code5"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;thumb.php?p=urunler/wall1.jpg&amp;h=200&quot; /&gt;</pre></td></tr></table></div>

<p>Dosya Adı: wall1_h200.jpg<br />
Genişlik: 267px<br />
Yükseklik: 200px<br />
<a href="test/thumb/thumbtest.php?1" target="_blank">Kodun çalışan halini görmek için tıklayın</a>
</div>
<hr />
<div style="overflow:auto; margin-bottom:8px;">

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p183code6'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1836"><td class="code" id="p183code6"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;thumb.php?p=urunler/wall1.jpg&amp;w=200&quot; /&gt;</pre></td></tr></table></div>

<p>Dosya Adı: wall1_w200.jpg<br />
Genişlik: 200px<br />
Yükseklik: 150px<br />
<a href="test/thumb/thumbtest.php?2" target="_blank">Kodun çalışan halini görmek için tıklayın</a>
</div>
<hr />
<div style="overflow:auto; margin-bottom:8px;">

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p183code7'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1837"><td class="code" id="p183code7"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;thumb.php?p=urunler/wall1.jpg&amp;w=200&amp;h=200&quot; /&gt;</pre></td></tr></table></div>

<p>Dosya Adı: wall1_w200_h200.jpg<br />
Genişlik: 200px<br />
Yükseklik: 200px<br />
<a href="test/thumb/thumbtest.php?3" target="_blank">Kodun çalışan halini görmek için tıklayın</a>
</div>
<hr />
thumb.php</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p183code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1838"><td class="code" id="p183code8"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #009933; font-style: italic;">/**
 * 	Dosya			= thumb.php
 *	Yazan			= Tuncay KINALI (a.k.a. Sniper)
 *	Görevi			= Parametre olarak verilen resmi istenilen boyutlarda küçültme, büyütme ve
 *			  		  orantılı olarak resmin içinden bir bölümü gösterme. Oluşturulan son resim
 *					  dosyasını yeniden isimlendirerek kaydetme. Sonraki çağırılışında bu isimde
 *					  dosya bulunduğu takdirde direkt olarak o dosyayı gösterme.
 *	Parametreler	= &quot;p&quot;: Üzerinde oynanacak resmin yolu
 *					  &quot;w&quot;: Resmin maximum genişliği (opsiyonel)
 *					  &quot;h&quot;: Resmin maximum yüksekliği (opsiyonel)
 *	Tarih			= 11.08.2007
 * 	Son Güncelleme 	= 27.08.2009 - 21:11
 */</span>
&nbsp;
<span style="color: #990000;">error_reporting</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Gösterilecek resmin yolu.</span>
<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'p'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Resmin istenilen genişliği.</span>
<span style="color: #666666; font-style: italic;">// Olası kötü amaçlı kullanımlara karşı maximum genişliği 1024px olarak ayarlıyoruz.</span>
<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1024</span> ? <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">:</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Resmin istenilen yüksekliği</span>
<span style="color: #666666; font-style: italic;">// Olası kötü amaçlı kullanımlara karşı maximum yüksekliği 768px olarak ayarlıyoruz</span>
<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">768</span> ? <span style="color: #cc66cc;">768</span> <span style="color: #339933;">:</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Belirtilen resim dosya sisteminde varsa...</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Dosya adını ve uzantısını ayrı ayrı al.</span>
	<span style="color: #000088;">$dosyaAdi</span> 	<span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$uzanti</span> 	<span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Thumbnail dosya adını öğren</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Thumbnail dosya adı, scriptin sonraki çalışmasında kontrol edeceği
	 * içinde istenilen genişliğin ve yüksekliğin belirtildiği isimdir.
	 * Örneğin thumb.php?p=resim.jpg&amp;w=100&amp;h=75 şeklinde çalıştırılan script
	 * için thumbnail dosya adı &quot;resim_100_75.jpg&quot; olarak belirlenecektir.
	 */</span>
	<span style="color: #000088;">$thumbFileName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dosyaAdi</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$thumbFileName</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$w</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span> ? <span style="color: #0000ff;">'_w'</span><span style="color: #339933;">.</span><span style="color: #000088;">$w</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$thumbFileName</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$h</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span> ? <span style="color: #0000ff;">'_h'</span><span style="color: #339933;">.</span><span style="color: #000088;">$h</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$thumbFileName</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$uzanti</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// İstenilen ölçülerde thumbnail daha önce talep edilmiş ve dosya sistemine kaydedilmişse...</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$thumbFileName</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// ... thumbnail dosyasına yönlen ve çalışmayı durdur.</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: <span style="color: #006699; font-weight: bold;">{$thumbFileName}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// ... ilk defa talep edilen thumbnail dosyası için çalışmaya başla</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Resmin bilgilerini al</span>
		<span style="color: #000088;">$resim</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Max. Genişlik manuel olarak belirtilmiş ve yükseklik belirtilmemişse...</span>
			<span style="color: #666666; font-style: italic;">// ... genişliği istenilen ölçüye getir ...</span>
			<span style="color: #000088;">$genislik</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$w</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// ... yüksekliği genişliğe orantılı bir şekilde hesapla.</span>
			<span style="color: #000088;">$yukseklik</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$genislik</span><span style="color: #339933;">*</span><span style="color: #000088;">$resim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #000088;">$resim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$w</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Max. Yükseklik manuel olarak belirtilmişse ve genişlik belirtilmemişse</span>
			<span style="color: #666666; font-style: italic;">// ... yüksekliği istenilen ölçüye getir ...</span>
			<span style="color: #000088;">$yukseklik</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$h</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// ... genişliği yüksekliğe orantılı bir şekilde hesapla.</span>
			<span style="color: #000088;">$genislik</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yukseklik</span><span style="color: #339933;">*</span><span style="color: #000088;">$resim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #000088;">$resim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Her iki özellikte manuel olarak belirtilmişse ...</span>
			<span style="color: #666666; font-style: italic;">// ... özellikleri istenilen ölçüye getir.</span>
			<span style="color: #000088;">$yukseklik</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$h</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$genislik</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$w</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Her iki ölçü de girilmemişse ana resme git ve çalışmayı durdur.</span>
			<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Resmin türüne göre ana resmi belleğe kopyala</span>
		<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// GIF</span>
				<span style="color: #000088;">$kopya_resim</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromgif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$resim_mime_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'image/gif'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// JPG</span>
				<span style="color: #000088;">$kopya_resim</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$resim_mime_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// PNG</span>
				<span style="color: #000088;">$kopya_resim</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$resim_mime_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'image/png'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Belirlenen ölçülerde boş bir resim oluştur</span>
		<span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$genislik</span><span style="color: #339933;">,</span> <span style="color: #000088;">$yukseklik</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Belleğe kopyalanan ana resmi istenilen ölçülere göre küçülterek oluşturulan resmi</span>
		<span style="color: #666666; font-style: italic;">// az önce oluşturduğumuz boş resmin içine yazdır.</span>
		<span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$thumb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$kopya_resim</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$genislik</span><span style="color: #339933;">,</span> <span style="color: #000088;">$yukseklik</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #009933; font-style: italic;">/**
			 * Eğer maximum yükseklik değeri manuel olarak girilmişse ve bu değer
			 * scriptin oluşturduğu değerden farklıysa scriptin otomatik değeri yoksayılıp
			 * elle girilen değer dikkate alınarak thumbnail yeniden boyutlandırılır
			 */</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yukseklik</span><span style="color: #339933;">&gt;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$yukseklik</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$h</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$thumb2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$genislik</span><span style="color: #339933;">,</span> <span style="color: #000088;">$yukseklik</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #990000;">imagecopy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$thumb2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$thumb</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #339933;">-</span><span style="color: #000088;">$yukseklik</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$genislik</span><span style="color: #339933;">,</span> <span style="color: #000088;">$yukseklik</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$sonuc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$thumb2</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$sonuc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$thumb</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009933; font-style: italic;">/** İstenilen boyuttaki thumbnail artık hazır
		 * Resmin türüne göre oluşturulan thumbnaili dosya sistemine yazdırmayı deneyeceğiz.
		 * Resmin bulunduğu klasörün yazma izinleri verilmişse thumbnail dosyası yukarıda
		 * ayarlanan isimle klasöre kaydedilir ve script kaydedilen bu dosyaya yönlendikten sonra
		 * çalışmayı durdurur. Yazma izinlerinde sorun varsa -ki bu scriptin esprisini yok eder-
		 * oluşturulan thumbnail'i direkt olarak browser'a yollar ve her seferinde yukarıdaki işlemleri yapar
		 */</span>
&nbsp;
		<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resim</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// GIF</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sonuc</span><span style="color: #339933;">,</span><span style="color: #000088;">$thumbFileName</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$thumbFileName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: <span style="color: #006699; font-weight: bold;">{$resim_mime_type}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sonuc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// JPG</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sonuc</span><span style="color: #339933;">,</span><span style="color: #000088;">$thumbFileName</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$thumbFileName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: <span style="color: #006699; font-weight: bold;">{$resim_mime_type}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sonuc</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// PNG</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sonuc</span><span style="color: #339933;">,</span><span style="color: #000088;">$thumbFileName</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$thumbFileName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: <span style="color: #006699; font-weight: bold;">{$resim_mime_type}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sonuc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Tüm işlemler bittikten sonra bellek boşaltılıp bir nebze olsun sunucu rahatlatılır</span>
		<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sonuc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://tuncay.kinali.net/php-ile-otomatik-thumbnail-olusturun.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
