lcd160 best script for display photo

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

lcd160 best script for display photo

Post by IHOXOHI » Wed Apr 29, 2020 9:37 pm

Hi,
I have written scripts for rezise and display all photos of a folder on lcd160 with a pyboard.
It produce a deformation of photos... I have start to write something without deformation but I prefer ask there before produce more efforts... if simply somebody has better...

Thanks.

The first one rezise photo in bash language:

Code: Select all

#!/bin/bash
###script for rezise photos in "photos"'s folder for after can display them on lcd160 (160x128, no exif, color YCBr, taille < 15000 bytes (depend of the original quality, could need to be change))


###dependances: imagemagick, jhead


####creation of a new folder wich will contain alls rezised photos

cd photos/
mkdir lcd-photos


###rezise photo in good size, and a quality correct for me (depend of the quality of the original), and color's mode.

for file in *.jpg;
do
  convert -resize 128x160\! -quality 70 -colorspace YCbCr $file lcd-photos/lcd-$file
done

###without deformation test

#cd $folder_name

#for file in *.jpg;
#do
#  convert -resize 128x160 -quality 50 -colorspace YCbCr $file lcd-photos/lcd-$file
#done
#cd lcd-photos/
#for file in *.jpg;
#do
#  composite -size 128x160 -xc: black -gravity center -colorspace YCbCr $file lcd-$file
#done


####destruction of exif data

cd lcd-photos  ###ou non si utilisation marges...
for file in *.jpg;
do
  jhead -purejpg $file
done
Maybe it's better in python language... But after, if photos are rights, it implicate a harder display for manage correctly orientation.
If someone has make it yet...

The second one run on pyboar and display alls photos:

Code: Select all

from lcd160cr import LCD160CR, PORTRAIT
from time import sleep
import os

os.chdir("/sd/photos")

buf = bytearray(15000)

def traitement_photo(photo):
    with open(photo, 'rb') as f:
      f.readinto(buf)
    lcd = LCD160CR('X')
    lcd.set_orient( PORTRAIT )
    lcd.erase()
    lcd.set_pos(0, 0)
    lcd.jpeg(buf)


while True:
  for photo in os.listdir():
     traitement_photo(photo)
     sleep(30)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: lcd160 best script for display photo

Post by jimmo » Thu Apr 30, 2020 12:59 am

IHOXOHI wrote:
Wed Apr 29, 2020 9:37 pm
It produce a deformation of photos..
Could you explain what you mean by "deformation" here? Is something going wrong with the display?
IHOXOHI wrote:
Wed Apr 29, 2020 9:37 pm
The first one rezise photo in bash language:
It's probably best to do the resizing before copying the files to the device, so you don't have to store more data than necessary. (Although I see you're using an SD card).
IHOXOHI wrote:
Wed Apr 29, 2020 9:37 pm
The second one run on pyboar and display alls photos:

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: lcd160 best script for display photo

Post by pythoncoder » Thu Apr 30, 2020 7:38 am

The problem may be that the aspect ratio of the pictures differs from that of the display.

If so, there is little option other than to process the pictures manually in something like gimp as changing the aspect ratio without distortion means cutting some of the picture out. The choice of what to exclude can't really be automated. Using gimp you can output pictures with exactly 160*128 pixels which should be displayed perfectly.
Peter Hinch
Index to my micropython libraries.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: lcd160 best script for display photo

Post by IHOXOHI » Fri May 01, 2020 7:13 am

Hi,
Thanks for yours responses...
Jimmo, in fact there is a little deformation of photos in portrait orientation which could be easy to corrige. For photos in landscape orientation, these have a little cut of border and no deformation.
Finally I think, it's not too hard for corrige these problems, but after I don't known how can I check the orientation
of photos for display them correctly on the pyboard, in automatic way... If it isn't possible, I prefers to not produce effort for nothing.

For moment the result is not too bad..

Peter, I have try to use gimp with automatics commands, and it's really too hard for me. I don't understand how it works. If it works...
Well, I produce a lots of photos and I can't manage them one by one.
If you known a good documentation for automatics commands in gimp, I will be happy.

So finally, the biggest problem is : is it possible to check orientation of a photo and display it with a script in micropython language?

Thanks a lots.
Have a fun.

bweatherall
Posts: 1
Joined: Fri May 01, 2020 1:07 pm

Re: lcd160 best script for display photo

Post by bweatherall » Fri May 01, 2020 3:21 pm

Wondering if you might have some luck working with ImageMagick https://imagemagick.org/ to do some resizing as well? It might provide a bit better API for automating. Just an idea to check out.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: lcd160 best script for display photo

Post by IHOXOHI » Sat May 02, 2020 4:03 pm

Hi,
If somebody need the touch-screen for display...

Code: Select all

import lcd160cr
import os
from time import sleep

path = "/sd/photos"
dirs = os.listdir(path)
os.chdir("/sd/photos")

global liste_photo
liste_photo = []
for i in dirs:
  liste_photo.append(i)
nombre_photos = len(liste_photo)

buf = bytearray(30000)

lcd = lcd160cr.LCD160CR('X')
lcd.set_orient( lcd160cr.PORTRAIT )

global j
j = 0

def affichage_photo():
  lcd.erase()
  lcd.set_pos(0, 0)
  lcd.jpeg(buf)
  

while True:
  photo = liste_photo[j]
  etat = lcd.is_touched()
  with open(photo, 'rb') as f:
    f.readinto(buf)
  if etat == True:
    affichage_photo()
    j += 1
  if j == nombre_photos:
    j = 0
  sleep(0.3)
    
I have goods photos witch produce goods results on the lcd160... Alls are free at photogeny.com...
Enjoy!

Post Reply