View photos in Python and html

Overview

I use a Macbook pro 13inch retina, and manage photos taken with an iPad or digital camera using the "photo app" that comes with the Mac. However, from the need to collect only the photos of one group such as girlfriend's photos in another folder for management and viewing, I made a program to display the JPG image copied to one folder as a thumbnail in html. I tried it. I haven't actually created thumbnails, just displayed them in small size on html.

It can also be used to store and manage the original image as it is, with the brightness corrected for ornamental purposes. By the way, the following is the command of ImageMagick, which is a command to brighten a dark photo. The larger the number, the brighter it is.

convert IMG_0461.JPG  -sigmoidal-contrast 10,0%  IMG_0461.jpg
convert IMG_0494.JPG  -sigmoidal-contrast  7,0%  IMG_0494.jpg
convert IMG_0333.JPG  -sigmoidal-contrast  4,0%  IMG_0333.jpg

Programming concept

Source code

py_pic.py


import os
from PIL import Image
 
filenames = os.listdir('./')
imgl=[]
ww=[]
hh=[]
for fname in sorted(filenames):
    path, ext = os.path.splitext( os.path.basename(fname) )
    if ext=='.JPG' and path[0:2]!='._':
        pic=path+ext
        im=Image.open(pic)
        w=im.size[0]
        h=im.size[1]
        print(pic, w, h)
        imgl=imgl+[pic]
        ww=ww+[w]
        hh=hh+[h]

f=open('maggie.html','w')
print('<html>',file=f)
print('<body>',file=f)
print('<table>',file=f)
n=len(imgl)
m=int(n/5)+1
k=-1
for i in range(0,m):
    print('<tr>',file=f)
    for j in range(0,5):
        k=k+1
        if k<=n-1:
            pic=imgl[k]
            w1=200
            h1=int(hh[k]/ww[k]*200)
            print('<td align="center"><img src="'+pic+'" alt="pic" width="'+str(w1)+'", height="'+str(h1)+'"><br><a href="'+pic+'">I'+pic+'<a></td>',file=f)
        else:
            print('<td></td>',file=f)
    print('</tr>',file=f)
print('</table>',file=f)
print('</body>',file=f)
print('</html>',file=f)
f.close()

that's all

Recommended Posts

View photos in Python and html
Receive and display HTML form data in Python
Stack and Queue in Python
Unittest and CI in Python
Difference between list () and [] in Python
Difference between == and is in python
Sorting algorithm and implementation in Python
Manipulate files and folders in Python
About dtypes in Python and Cython
Assignments and changes in Python objects
Check and move directories in Python
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
Function synthesis and application in Python
Export and output files in Python
Reverse Hiragana and Katakana in Python2.7
Reading and writing text in Python
[GUI in Python] PyQt5-Menu and Toolbar-
Create and read messagepacks in Python
Overlapping regular expressions in Python and Java
Differences in authenticity between Python and JavaScript
Notes using cChardet and python3-chardet in Python 3.3.1.
Modules and packages in Python are "namespaces"
Avoid nested loops in PHP and Python
Differences between Ruby and Python in scope
AM modulation and demodulation in Python Part 2
difference between statements (statements) and expressions (expressions) in Python
Eigenvalues and eigenvectors: Linear algebra in Python <7>
Implementation module "deque" in queue and Python
Line graphs and scale lines in python
Implement FIR filters in Python and C
Differences in syntax between Python and Java
Check and receive Serial port in Python (Port check)
Search and play YouTube videos in Python
Difference between @classmethod and @staticmethod in Python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
Write O_SYNC file in C and Python
Dealing with "years and months" in Python
(Python) HTML reading and regular expression notes
Read and write JSON files in Python
Easily graph data in shell and Python
Private methods and fields in python [encryption]
Find and check inverse matrix in Python
Linear Independence and Basis: Linear Algebra in Python <6>
Call sudo in Python and autofill password
Differences in multithreading between Python and Jython
Convert from Markdown to HTML in Python
Module import and exception handling in python
[python] Read html file and practice scraping
How to use is and == in Python
Project Euler # 1 "Multiples of 3 and 5" in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python