Generating thumbnails from a collection of pictures is an easy task and there are many tools for the job. But I didn’t find a tool who can clip out a centered box of my pictures to get quadratic thumbs of my originals. Because I am a developer and I dont want to try out many tools: I will hack a short python script (with help of the PIL) myself. simple solution The following python script can be f
Here’s a simple django view which creates a PIL image on the fly, and returns it as a PNG image: from django.utils.httpwrappers import HttpResponse from PIL import Image import random INK = "red", "blue", "green", "yellow" def image(request): # ... create/load image here ... image = Image.new("RGB", (800, 600), random.choice(INK)) # serialize to HTTP response response = HttpResponse(mimetype="imag
Django thumbnails, resize image with PIL and python There is a wide variety of django filters and tags to crop, resize or make a thumbnail out of an image but most of them seem to reinvent the wheel. #!/usr/bin/env python try: from PIL import Image, ImageOps except ImportError: import Image import ImageOps image = Image.open('snake.jpg') # ImageOps compatible mode if image.mode not in ("L", "RGB")
« Return to page index Python Imaging Library Handbookã®ä¸€éƒ¨ã§ã‚ã‚‹ãƒãƒ¥ãƒ¼ãƒˆãƒªã‚¢ãƒ«ã®è¶…訳ã§ã™ã€‚ Imageクラスを使ㆠPILã«ãŠã„ã¦æœ€ã‚‚é‡è¦ãªImageクラス PILã«ãŠã„ã¦æœ€ã‚‚é‡è¦ãªã‚¯ãƒ©ã‚¹ã¯Imageクラスã§ã™ã€‚ã“ã‚Œã¯åŒã˜åå‰ã®ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã®ä¸ã§å®šç¾©ã•ã‚Œã¦ã„ã¾ã™ã€‚ã‚ãªãŸã¯ä¾‹ãˆã°ãƒ•ã‚¡ã‚¤ãƒ«ã‹ã‚‰ç”»åƒã‚’èªã¿è¾¼ã‚“ã ã‚Šã€ä»–ã®ç”»åƒã‚’処ç†ã—ãŸã‚Šã€ã‚¹ã‚¯ãƒ©ãƒƒãƒã‹ã‚‰ç”»åƒã‚’生æˆã—ãŸã‚Šã™ã‚‹ã“ã¨ã«ã‚ˆã£ã¦ã“ã®ã‚¯ãƒ©ã‚¹ã®ã‚¤ãƒ³ã‚¹ã‚¿ãƒ³ã‚¹ã‚’生æˆã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚ ファイルを画åƒã‹ã‚‰èªã¿è¾¼ã‚€ãŸã‚ã«ã¯ã€Imageモジュールã®open関数を使ã„ã¾ã™ã€‚ >>> import Image >>> im = Image.open("lena.ppm") openã«æˆåŠŸã™ã‚‹ã¨ã€open関数ã¯Imageオブジェクトを返ã—ã¾ã™ã€‚ãã†ã™ã‚Œã°ã‚ãªãŸã¯ãƒ•ã‚¡ã‚¤ãƒ«ã®ä¸èº«ã‚’調ã¹ã‚‹ãŸã‚ã«ã‚¢ãƒˆãƒªãƒ“ュートを使
Python Image Library - Examples import Image global ext ext = ".jpg" imageFile = "test.jpg" im1 = Image.open(imageFile) Original image Resize def imgResize(im): div = 2 width = im.size[0] / div height = im.size[1] / div im2 = im.resize((width, height), Image.NEAREST) # use nearest neighbour im3 = im.resize((width, height), Image.BILINEAR) # linear interpolation in a 2x2 environment im4 = im.resize
Last week, I was trying to find out how to get my photo’s metadata. I had noticed that Windows could display the camera model, creation date and lots of other data on my photos, but I couldn’t remember what that data was called. I finally found what I was looking for. The term is EXIF (Exchangeable Image File Format). For this post, we’ll take a look at the various 3rd party packages that give you
Python Imaging Libraryã®é–¢æ•°ã‚’使ã„ãªãŒã‚‰ã®ãƒ¡ãƒ¢ã§ã™ã€‚ テスト用ã®ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«TestPIL.pyを作æˆã—ã€åŒã˜ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã«å…¨ã¦åŒã˜ã‚µã‚¤ã‚ºã®é©å½“ãªRGBç”»åƒ"test.bmp","test2.bmp","mask.bmp"を用æ„ã—ã¦å®Ÿè¡Œã—ã¦ã¿ã¾ã—ãŸã€‚以下使ãˆãã†ãªé–¢æ•°ã‚’ã²ãŸã™ã‚‰ãƒ”ックアップ&リストアップ。関数ã®æ›¸ãæ–¹ã¯ã€å¤‰æ•°å:åž‹ã€é–¢æ•°å(引数å:引数型):è¿”å´å€¤åž‹ã¨ã„ã†è¡¨è¨˜ã‚’使ã†ã“ã¨ã«ã—ã¾ã™ã€‚ モジュールã®ã‚¤ãƒ³ãƒãƒ¼ãƒˆ from PIL import Image Imageクラスã®ãƒ¡ãƒ³ãƒå¤‰æ•° format:string ç”»åƒãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆ mode:string 階調。"1":2値画åƒ,"L":グレースケール,"RGB","CMYK"ãªã© size:turple (width, height) ç”»åƒã‚µã‚¤ã‚º pallete:palette ç”»åƒãƒ¢ãƒ¼ãƒ‰ãŒ"P"ã®ã¨ã
ç”»åƒãŒç·¨é›†ã§ãるらã—ã„ã®ã§å®Ÿé¨“。 snow.jpgを縮å°ã€‚ 640*480ãªã®ã§ç¸¦200ãらã„ã«ã—ã¦ã¿ã‚‹ã€‚ >>> import Image >>> snow = Image.open(r"C:\pyphot\snow.jpg") >>> snow.thumbnail((200,200),Image.ANTIALIAS) >>> snow.save(r"C:\pyphot\snow_resize.jpg") ã§ããŸã€‚ フォルダã«å…¥ã£ã¦ã‚‹.jpgを全部一度ã«åŒã˜ã‚µã‚¤ã‚ºã«ãƒªã‚µã‚¤ã‚ºå‡ºæ¥ãªã„ã‹ãªï¼Ÿ ん~ 考ãˆã¦ã¿ã‚ˆã†ã€‚
リリースã€éšœå®³æƒ…å ±ãªã©ã®ã‚µãƒ¼ãƒ“スã®ãŠçŸ¥ã‚‰ã›
最新ã®äººæ°—エントリーã®é…ä¿¡
処ç†ã‚’実行ä¸ã§ã™
j次ã®ãƒ–ックマーク
kå‰ã®ãƒ–ックマーク
lã‚ã¨ã§èªã‚€
eコメント一覧を開ã
oページを開ã
{{#tags}}- {{label}}
{{/tags}}