I wrote this to demo a quick #Python#Pillow#PIL conversion of an image to grayscale with a dialog to select the file... then applied it to a picture of me and @rennerocha
taken by John as we were flying back home after wonderful #PyConUS24 :)
from tkinter.filedialog import askopenfilename<br></br>from pathlib import Path<br></br><br></br>from PIL import Image<br></br><br></br># Open a select file dialog (a bit ugly on my OS)<br></br>file_path_str = askopenfilename() # '' if cancelled<br></br>if file_path_str: # guards against a cancelled dialog<br></br> file_path = Path(file_path_str) # a pathlib.Path object from the str<br></br> new_name = file_path.stem + '_altered' + file_path.suffix # keep suffix<br></br> # Make it output a PNG if you want LA mode to keep alpha<br></br> # new_name = file_path.stem + '_altered.png' maybe I should check for PNGs?<br></br> output_path = file_path.parent / new_name<br></br> try: # to handle any exceptions (runtime errors while converting/saving)<br></br> with Image.open(file_path) as im: # load image<br></br> altered_im = im.convert('L') # to grayscale (use 'LA' to keep alpha)<br></br> altered_im.save(output_path) # save image<br></br> print(f'Saved {output_path.name}!')<br></br> except Exception as err: # ... treat exception<br></br> print(err)<br></br>
Back to the succulent pillow project - time to sew all the pieces together! I'm figuring it out as I go along, as this is my first time sewing crochet, and the pattern I'm using doesn't really have any guidance.
Liebe Menschen, die Dinge mit Python3 und Fotos machen: Gibt es einen Trick, die Größe eines Fotos zu ermitteln, das keine EXIF-Daten (oder andere Meta-Daten) hat?
Hintergrund: Ich möchte Fotos, die ich vorher gescannt habe, für einen bestimmten Zweck runterskalieren. Dazu verwende ich meinen downscaler (https://git.atari-frosch.de/?p=downscaler.git;a=tree). Der verläßt sich allerdings auf PIL, ergo auf vorhandene EXIF-Daten. Bei Scans hab ich die natürlich nicht.
downscaler meint, die Dateien seien schon zu klein, aber da muß ich nochmal nachschauen, warum das Fehlen der EXIF-Daten so interpretiert wird.
A new ImageOps.cover method has been added, that a resized version of the image, so that the requested size is covered, while maintaining the original aspect ratio.
Pillow had a “better than nothing” default font. Now, if FreeType is available, a version of Aileron Regular is loaded, which can be drawn at chosen font sizes.
Maybe next time don't sink your entire #pillow#fortune into absurd #conspiracytheories, and expensive #lawsuits that go nowhere. As a spectator, watching Mike Pillow lose it all has been very entertaining.
Pillow Craft Artisan Keycaps
[Jelly Key][In-stock sale] Pillow Craft Artisan Keycaps...