Skip to content

Commit 1f04dd6

Browse files
committed
Get borders fixed and nonsquare pixels
1 parent 6b65985 commit 1f04dd6

6 files changed

+21
-18
lines changed

DIMENSIONS

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
788x458
2+
should be 800x480

canvas-slideshow.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ function updateMainImage() {
4848
var sw = nw / cw;
4949
var sh = nh / ch;
5050
if (nh <= ch && nw <= cw) {
51-
var wo = 10; // adjust for un-asked-for left border
52-
var x = Math.floor((cw-nw)/2);
53-
x = x - wo;
54-
if (x < 0) {
55-
x = 0;
56-
}
57-
context.drawImage(theImage,x,(ch-nh)/2,nw,nh);
51+
context.drawImage(theImage,(cw-nw)/2,(ch-nh)/2,nw,nh);
5852
}
5953
else { // need to scale something to fit
6054
if (sw >= sh) {

canvas.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
canvas {
99
border: 0px solid black;
1010
}
11+
html, body, webview {
12+
margin: 0;
13+
padding: 0;
14+
border: 0;
15+
display: block;
16+
width: 100%;
17+
height: 100%;
18+
}
1119
html {
1220
background-color: #000000;
1321
}
@@ -27,7 +35,7 @@
2735
<script src="canvas-slideshow.js"></script>
2836
</head>
2937
<body>
30-
<canvas id="mainimage" width="800" height="460"></canvas>
38+
<canvas id="mainimage" width="800" height="480"></canvas>
3139
</body>
3240
</html>
3341

make-slidelist.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
# do all searching inside this top level dir
1212
top_dir = '/home/pi/photo/'
1313
# look in these subdirectories of top_dir
14-
# subdirs = ['2017', '2016', '2015', '2014']
15-
subdirs = ['2017', '2016', '2015']
14+
subdirs = ['2019', '2018', '2017', '2016', '2015', '2014']
1615
# filename must end in one of these suffixes
1716
suffixes = ['.jpg', '.JPG', '.gif', '.GIF', '.png', '.PNG']
1817
# exclude any file that has these substrings

resize-pic-dir.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
# max width and height of downsized pics
1313
max_width = 800
14-
max_height = 460
14+
max_height = 480
1515
# RPi touchscreen is 800x480 pixels in 155x86mm
1616
pixel_ratio = (800.0/155.0) / (480.0 / 86.0)
1717

1818
# top-level dir to find the source pics...include trailing slash
1919
top_src_dir = '/mnt/photo/'
2020
# look in these subdirectories of top_src_dir
21-
src_subdirs = ['2017', '2016', '2015']
21+
src_subdirs = ['2019', '2018', '2017', '2016', '2015']
22+
#src_subdirs = ['test']
2223

2324
# top-level dir to put the resized pics
2425
top_dst_dir = '/home/pi/photo/'
@@ -58,7 +59,7 @@
5859
print("{} already exists".format(full_dst_name))
5960
continue
6061
print("{} -> \n {}".format(full_src_name, full_dst_name))
61-
command = "./resize-pic.py {} {} {} {} 7 7 {}".format(full_src_name, max_width, max_height, pixel_ratio, full_dst_name)
62-
# print("command is {}".format(command))
62+
command = "./resize-pic.py {} {} {} {:.4f} 7 7 {}".format(full_src_name, max_width, max_height, pixel_ratio, full_dst_name)
63+
print("command is {}".format(command))
6364
os.system(command)
6465

resize-pic.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
if (src_width > src_height):
6262
dst_width = max_width
6363
scale = float(dst_width)/float(src_width)
64-
dst_height = int(src_height*scale*pixel_ratio)
64+
dst_height = int(src_height*scale/pixel_ratio)
6565

6666
# if downscaled height fits within max_height, rescale and save
6767
if (dst_height <= max_height):
@@ -90,9 +90,9 @@
9090
src_height = cropped.height
9191
dst_height = max_height
9292
scale = float(dst_height)/float(src_height)
93-
dst_width = int(src_width*scale/pixel_ratio)
93+
dst_width = int(src_width*scale*pixel_ratio)
9494
src_img.resize(dst_width,dst_height)
95-
print("Resized to {}x{}".format(dst_width,dst_height))
95+
print("After crop resized to {}x{}".format(dst_width,dst_height))
9696
src_img.save(filename=outfilename)
9797

9898
# if the pic is taller than wide:
@@ -103,7 +103,7 @@
103103
cropped = src_img[:,top_crop:(src_height-bottom_crop)]
104104
dst_height = max_height
105105
scale = float(dst_height)/float(cropped.height)
106-
dst_width = int(src_width*scale/pixel_ratio)
106+
dst_width = int(src_width*scale*pixel_ratio)
107107
cropped.resize(dst_width,dst_height)
108108
cropped.save(filename=outfilename)
109109

0 commit comments

Comments
 (0)