<?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>ftoptas blog &#187; text</title>
	<atom:link href="http://ftoptas.com/tag/text/feed/" rel="self" type="application/rss+xml" />
	<link>http://ftoptas.com</link>
	<description>[beta]</description>
	<lastBuildDate>Mon, 30 Jan 2012 20:19:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Python ile Resim Üzerine Yazı Yazma</title>
		<link>http://ftoptas.com/python-ile-resim-uzerine-yazi-yazma/</link>
		<comments>http://ftoptas.com/python-ile-resim-uzerine-yazi-yazma/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 10:01:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[imagedraw]]></category>
		<category><![CDATA[imagedraw.text]]></category>
		<category><![CDATA[pil]]></category>
		<category><![CDATA[resim üzerine yazı]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://ftoptas.com/?p=279</guid>
		<description><![CDATA[Python ile grafik işleme yapabilmek]]></description>
			<content:encoded><![CDATA[<p>Python ile grafik işleme yapabilmek için <a href="http://www.pythonware.com/products/pil/" target="_blank">PIL (Python Imaging Library) </a>kütüphanesini kullanıyoruz. Kütüphanenin işletim sistemi ve Python sürümümüze uygun olan versiyonunu indirip kuralım. Kütüphanenin doğru bir şekilde kurulup kurulmadığını test etmek için Python komut satırına şunu yazalım:</p>
<pre name="code" class="python">
import PIL
</pre>
<p>Herhangi bir hata vermediyse kütüphane yüklenmiştir. Şimdi işlem yapmaya başlayabiliriz.</p>
<pre name="code" class="python">
from PIL import Image
resim = Image.open("test.jpg")
print resim.size
</pre>
<p>(241,172)<br />
<span id="more-279"></span><br />
<img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test.jpg" alt="" width="241" height="172" /></p>
<p>Burada önce PIL içerisinden Image nesnesini çağırdık ve open fonksiyonuyla test.jpg resmini açtık. Resmin boyutlarını öğrenmek için size özelliğine bakarız. Image nesnesiyle kullanacağımız diğer metotlar için şunu yazabiliriz:</p>
<pre name="code" class="python">
dir(resim)
</pre>
<p>Resim üzerine bir yazı yazmak için de ImageDraw nesnesini kullanacağız. Bu yazının fontunu belirlemek için ImageFont nesnesini kullanacağız.</p>
<pre name="code" class="python">
from PIL import Image,ImageFont,ImageDraw
resim = Image.open("test.jpg")
f = ImageFont.truetype("arial.ttf", 35)
ciz = ImageDraw.Draw(resim)
ciz.text((10,10), "ftoptas.com", font=f, fill="#0C3446")
resim.save("test2.jpg")
</pre>
<p><img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test2.jpg" alt="" width="241" height="172" /></p>
<p>Önce yazacağımız yazının fontunu arial ve font büyüklüğünü de 20 olarak belirledik. Ardından 4. satırda açtığımız resmi kullanarak bir Draw nesnesi oluşturduk. Bu nesnenin text metodunu kullanarak (10,10) koordinatına &#8220;#0C3446&#8243; renginde ve ayarladığımız fontta yazı yazmış olduk. text metodunun parametreleri şu şekildedir:</p>
<p>text((x,y), &#8220;yazılacak metin&#8221;, font, renk)</p>
<p>Son olarak  yeni resmi test2.jpg olarak kaydediyoruz.</p>
<p>Yazıya biraz gölge efekti vermek için yazıyı iki defa farklı renkte ve x-y koordinatlarının 2 piksel arttırılmış olarak kaydedelim.</p>
<pre name="code" class="python">
from PIL import Image,ImageFont,ImageDraw
resim = Image.open("test.jpg")
f = ImageFont.truetype("arial.ttf", 35)
ciz = ImageDraw.Draw(resim)
ciz.text((8,8), "ftoptas.com", font=f, fill="#3EA3D1")
ciz.text((10,10), "ftoptas.com", font=f, fill="#0C3446")
resim.save("test3.jpg")
</pre>
<p><img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test3.jpg" alt="" width="241" height="172" /></p>
<p>Yazının arkasına açık renkli bir diktörtgen çizip yazının okunabilirliğini arttırabiliriz.</p>
<pre name="code" class="python">
from PIL import Image,ImageFont,ImageDraw
resim = Image.open("test.jpg")
f = ImageFont.truetype("arial.ttf", 35)
ciz = ImageDraw.Draw(resim)
ciz.rectangle(((8,8),(190,48)),fill="#ffffff")
ciz.text((8,8), "ftoptas.com", font=f, fill="#3EA3D1")
ciz.text((10,10), "ftoptas.com", font=f, fill="#0C3446")
resim.save("test4.jpg")
</pre>
<p><img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test4.jpg" alt="" width="241" height="172" /></p>
<p>Draw nesnesinin rectangle metodunu kullanarak belirtiğimiz koordinatlara bir diktörtgen oluşturduk. Yazıya bir açı vermek için şu yöntemi kullanabiliriz:</p>
<pre name="code" class="python">
from PIL import Image,ImageFont,ImageDraw
resim = Image.open("test.jpg")
f = ImageFont.truetype("arial.ttf", 20)
yazi = Image.new('RGB',(120,50))
ciz = ImageDraw.Draw(yazi)
ciz.text((8,8), "ftoptas.com", font=f, fill="#ffffff")
yazi = yazi.rotate(15)
resim.paste(yazi,(20,20))
resim.save("test5.jpg")
</pre>
<p><img class="alignnone" title="test" src="http://ftoptas.com/wp-content/uploads/2009/08/pil/test5.jpg" alt="" width="241" height="172" /></p>
<p>RGB formatında 120&#215;50 piksel boyutunda yeni bir Image oluşturup yazıyı onun içine yazdık. Ardından içinde yazı olan resme 15 derece açı verip eski resmin üzerinde yapıştırdık.</p>
]]></content:encoded>
			<wfw:commentRss>http://ftoptas.com/python-ile-resim-uzerine-yazi-yazma/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

