{"id":1,"date":"2023-01-14T00:19:38","date_gmt":"2023-01-14T00:19:38","guid":{"rendered":"http:\/\/bakirci.net\/?p=1"},"modified":"2023-03-13T22:13:02","modified_gmt":"2023-03-13T22:13:02","slug":"python-ile-resim-duzenleme","status":"publish","type":"post","link":"http:\/\/bakirci.net\/index.php\/2023\/01\/14\/python-ile-resim-duzenleme\/","title":{"rendered":"Python ile resim d\u00fczenleme"},"content":{"rendered":"\n<p><strong>Bir klas\u00f6r i\u00e7indeki resimleri istenen boyuta g\u00f6re d\u00fczenleyen ve resim \u00fczerine dosya ismini yazan python kodu.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from PIL import Image, ImageDraw, ImageFont\nimport os\n\n# Klas\u00f6r yolu, yeniden boyutland\u0131rmak istedi\u011fimiz geni\u015flik ve y\u00fckseklik, yaz\u0131 tipi ve yaz\u0131 boyutu\nfolder_path = \"\/Users\/macintosh\/Desktop\/Karsan\"\nnew_width = 200\nnew_height = 200\nfont_path = \"\/Library\/Fonts\"\nfont_size = 20\n\n# Klas\u00f6r i\u00e7indeki t\u00fcm dosyalar\u0131 listele\nfor filename in os.listdir(folder_path):\n    # Sadece JPEG dosyalar\u0131n\u0131 i\u015fle\n    if filename.endswith(\".jpg\") or filename.endswith(\".jpeg\"):\n        # Resmi a\u00e7\n        with Image.open(os.path.join(folder_path, filename)) as img:\n            # Boyutu yeniden boyutland\u0131r\n            img = img.resize((new_width, new_height))\n            \n            # Dosya ad\u0131n\u0131 al\n            file_name = os.path.splitext(filename)&#91;0]\n            \n            # Yaz\u0131 tipi ve boyutunu ayarla\n            font = ImageFont.truetype(\"Arial.ttf\", font_size)\n            \n            # Metnin boyutunu al\n            text_width, text_height = font.getsize(file_name)\n            \n            # Metni i\u00e7eren transparan bir kutu olu\u015ftur\n            text_box = Image.new('RGBA', (text_width, text_height), (255, 255, 255, 150))\n            \n            # Metni kutunun ortas\u0131na yerle\u015ftir\n            draw = ImageDraw.Draw(text_box)\n            draw.text((0, 0), file_name, font=font, fill=(0, 0, 0, 255))\n            \n            # Metin kutusunu resmin alt\u0131na yerle\u015ftir\n            img.paste(text_box, (int(new_width\/2 - text_width\/2), int(new_height * 0.9 - text_height\/2)), text_box)\n            \n            # Dosya boyutunu k\u00fc\u00e7\u00fcltmek i\u00e7in optimize et\n            img.save(os.path.join(folder_path, filename), optimize=True, quality=70)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Bir klas\u00f6r i\u00e7indeki resimleri istenen boyuta g\u00f6re d\u00fczenleyen ve resim \u00fczerine dosya ismini yazan python kodu.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":3,"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":12,"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/posts\/1\/revisions\/12"}],"wp:attachment":[{"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bakirci.net\/index.php\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}