photography:scripts
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Last revision | |||
— | photography:scripts [2012/06/15 07:22] – created cedric | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Compare folder contents ====== | ||
+ | ===== Find incoherence in your backups ===== | ||
+ | <code bash> | ||
+ | cedric@debian: | ||
+ | cedric@debian: | ||
+ | cedric@debian:/ | ||
+ | cedric@debian:/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Focal length repartition ====== | ||
+ | |||
+ | <code python> | ||
+ | # | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
+ | import pylab | ||
+ | import glob | ||
+ | from collections import Counter | ||
+ | |||
+ | from PIL import Image | ||
+ | from PIL.ExifTags import TAGS | ||
+ | |||
+ | |||
+ | DIRECTORY = "/ | ||
+ | |||
+ | |||
+ | def get_exif(fn): | ||
+ | ret = {} | ||
+ | i = Image.open(fn) | ||
+ | info = i._getexif() | ||
+ | if info is not None: | ||
+ | for tag, value in info.items(): | ||
+ | decoded = TAGS.get(tag, | ||
+ | ret[decoded] = value | ||
+ | return ret | ||
+ | |||
+ | |||
+ | |||
+ | if __name__ == " | ||
+ | cnt = Counter() | ||
+ | pictures = glob.glob(DIRECTORY) | ||
+ | focal = Counter() | ||
+ | for picture in pictures: | ||
+ | exif = get_exif(picture) | ||
+ | if exif != {}: | ||
+ | focal[exif[' | ||
+ | |||
+ | if focal: | ||
+ | length = len(focal) | ||
+ | ind = pylab.arange(length) | ||
+ | width = 0.35 # bars width | ||
+ | |||
+ | focal_list = [elem for elem in focal.keys()] | ||
+ | focal_count = [elem for elem in focal.values()] | ||
+ | max_focal_count = max(focal_count) | ||
+ | |||
+ | p = pylab.bar(ind, | ||
+ | |||
+ | pylab.ylabel(" | ||
+ | pylab.xlabel(" | ||
+ | pylab.title(" | ||
+ | pylab.xticks(ind + (width / 2), focal_list) | ||
+ | pylab.xlim(-width, | ||
+ | |||
+ | # changing the ordinate scale according to the max. | ||
+ | if max_focal_count <= 100: | ||
+ | pylab.ylim(0, | ||
+ | pylab.yticks(pylab.arange(0, | ||
+ | elif max_focal_count <= 200: | ||
+ | pylab.ylim(0, | ||
+ | pylab.yticks(pylab.arange(0, | ||
+ | elif max_focal_count <= 600: | ||
+ | pylab.ylim(0, | ||
+ | pylab.yticks(pylab.arange(0, | ||
+ | elif max_focal_count <= 800: | ||
+ | pylab.ylim(0, | ||
+ | pylab.yticks(pylab.arange(0, | ||
+ | |||
+ | |||
+ | for rect in p: | ||
+ | height = rect.get_height() | ||
+ | pylab.text(rect.get_x()+rect.get_width()/ | ||
+ | ha=' | ||
+ | |||
+ | |||
+ | pylab.show() | ||
+ | else: | ||
+ | print "No result." | ||
+ | </ | ||
+ | | ||
+ | | ||
+ | | ||
+ | ====== Piwigo ====== | ||
+ | |||
+ | <code python> | ||
+ | ! / | ||
+ | -*- coding: utf-8 -*- | ||
+ | |||
+ | """ | ||
+ | |||
+ | Usefull for your Piwigo gallery (http:// | ||
+ | |||
+ | ./piwigo | ||
+ | |||
+ | ./photos | ||
+ | ./ | ||
+ | ./pwg_high/ | ||
+ | ./ | ||
+ | . | ||
+ | . | ||
+ | ./ | ||
+ | ./piwigo.py | ||
+ | |||
+ | Resize images from /pwg_high (original images) directory in two size : | ||
+ | |||
+ | - 128*128 pixels in ./ | ||
+ | - 1024*768 pixels in ./ | ||
+ | |||
+ | """ | ||
+ | |||
+ | __author__ = " | ||
+ | __date__ = " | ||
+ | __copyright__ = " | ||
+ | __license__ = "GPL v3" | ||
+ | |||
+ | import re import os import Image | ||
+ | |||
+ | def search_files(motif, | ||
+ | |||
+ | """ | ||
+ | |||
+ | Search fo files containing ' | ||
+ | aren't symbolic links. | ||
+ | """ | ||
+ | result = [] | ||
+ | w = os.walk(root_path) | ||
+ | for (path, dirs, files) in w: | ||
+ | for f in files: | ||
+ | if re.compile(motif).search(f): | ||
+ | # if not a symbolic link | ||
+ | if not os.path.islink(os.path.join(path, | ||
+ | result.append((os.path.join(path, | ||
+ | return result | ||
+ | |||
+ | images = search_files(" | ||
+ | |||
+ | for image in images: | ||
+ | |||
+ | im = Image.open(image[0]) | ||
+ | |||
+ | im_thumbnail = im.resize((128, | ||
+ | im_thumbnail.save(" | ||
+ | |||
+ | im_slide = im.resize((1024, | ||
+ | im_slide.save(" | ||
+ | |||
+ | """ | ||
+ | |||
+ | Use nearest neighbour : | ||
+ | Image.NEAREST | ||
+ | Linear interpolation in a 2x2 environment : | ||
+ | Image.BILINEAR | ||
+ | Cubic spline interpolation in a 4x4 environment : | ||
+ | Image.BICUBIC | ||
+ | Best down-sizing filter : | ||
+ | Image.ANTIALIAS | ||
+ | |||
+ | """ | ||
+ | </ | ||
+ | |||
+ | On peut facilement ajouter le transfert FTP du résultat dans le dossier distant qui va bien. | ||
+ | |||
+ | |||
+ | ====== Watermark avec ImageMagick ====== | ||
+ | |||
+ | <code bash> | ||
+ | [cedric@localhost ~]$ convert 16-04-2008_0167.jpg -font Arial -pointsize 40 -draw " | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Effet Polaroid ====== | ||
+ | |||
+ | <code bash> | ||
+ | convert picture.jpg -thumbnail 240 -bordercolor white -background black +polaroid picture-pola.png | ||
+ | </ |
photography/scripts.txt · Last modified: 2022/01/02 12:05 by cedric