Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 01-27-2011, 01:40 PM   #1
soymicmic
Junior Member
soymicmic began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Dec 2010
Device: AmazonKindle 3
Linux script for images to Kindle Screensaver

I hope you find it useful.

This is a small python script to adapt the selected images to a format / size appropriate to act as screensaver Kindle 3.

Save it in /home/%USER%/.gnome2/nautilus-scripts

Download from: http://gtk-apps.org/content/show.php?content=137930
Spoiler:
Code:
#!/usr/bin/env python
# -*- coding: latin-1 -*-
# ==============================================================================================
# Convierte las imagenes seleccionadas a imagenes apropiadas para salvapantallas del Kindle 3
# ==============================================================================================

import gtk
import os, sys
import string

sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])),".."))
import Process

def alerta (cadena, tipo):
	dialogo = gtk.MessageDialog(None, gtk.DIALOG_MODAL, tipo, gtk.BUTTONS_CLOSE, cadena)
	dialogo.set_title("Imagenes Kindle 3")
	dialogo.run()
	dialogo.destroy()

def ClickAceptar(widget):
	archivos = os.environ['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'].split("\n")
	for archivo in archivos:
		if archivo != "":
			if os.path.isdir(archivo):
				ProcesarDirectorio(archivo)
			else:
				ProcesarImagen(archivo)

	alerta("El proceso ha finalizado satisfactoriamente.", gtk.MESSAGE_INFO)
	gtk.main_quit()

def ClickCancelar(widget):
	gtk.main_quit()

def ProcesarDirectorio(directorio):
	archivos = os.listdir(directorio)
	for archivo in archivos:
		archivo = directorio + "/" + archivo
		if os.path.isdir(archivo):
			ProcesarDirectorio(archivo)
		else:
			ProcesarImagen(archivo)

def ProcesarImagen(archivo):
	if Process.getExtension(archivo) == "JPG" or Process.getExtension(archivo) == "PNG" or Process.getExtension(archivo) == "BMP":

		# Construimos nombre de fichero resultado
		destino = Process.getPath(archivo) + "/kindle_" + Process.getName(archivo) + ".png"

		# rotamos si es necesario para mantener la mejor resolucion, ademas trabajamos con ficheros png
		pb=gtk.gdk.pixbuf_new_from_file(archivo)
		if pb.get_height()<pb.get_width():
			opcGiro = "-rotate -90"
		else:
			opcGiro = ""

		Process.ProcessFileByArgument("convert " + opcGiro + " \"" + archivo + "\" \"" + destino + "\"")
		
		# pasamos a grises y ajustamos tamaño
#		Process.ProcessFileByArgument("convert -colorspace Gray -resize 550x750> -gravity center -background Gray -extent 550x750 \"" + destino + "\" \"" + destino + "\"")
		Process.ProcessFileByArgument("convert -colorspace Gray -resize 600x800> -gravity center -background Gray -extent 600x800 \"" + destino + "\" \"" + destino + "\"")

		# añadimos borde en negro para completar 600x800
#		Process.ProcessFileByArgument("convert -border 25x25 -bordercolor black \"" + destino + "\" \"" + destino + "\"")

		# añadimos texto centrado en la base y con espaciado entre letras
		titulo=" Slide and release the power switch to wake "
		Process.ProcessFileByArgument("convert -kerning 2 -font Ubuntu-Regular -fill white -undercolor black -pointsize 20 -draw \"gravity south text 0,0 '" + titulo + "'\" \"" + destino + "\" \"" + destino  + "\"")

		# añadimos credito en vertical
		credito=" " + entryName.get_text() + " "
		Process.ProcessFileByArgument("convert -font Ubuntu-Regular -fill white -undercolor gray -pointsize 12 -draw \"translate 590,150 rotate -90 text 0,0 '" + credito + "'\" \"" + destino + "\" \"" + destino + "\"")

		# añadimos titulo de imagen en vertical
		nombre=" " + Process.getName(archivo) + " "
		if cbNomFic.get_active()==True:
			Process.ProcessFileByArgument("convert -font Ubuntu-Regular -fill white -undercolor gray -pointsize 15 -draw \"translate 20,775 rotate -90 text 0,0 '" + nombre + "'\" \"" + destino + "\" \"" + destino + "\"")
		else:
			nombre=""

	else:
		alerta(archivo + "\n\nTipo no soportado.", gtk.MESSAGE_WARNING)

# PROGRAMA

if Process.verifyCommands("convert%ImageMagick")==False:
	sys.exit()

w = gtk.Window(gtk.WINDOW_TOPLEVEL)
w.set_title("Imagenes Kindle 3")
w.set_border_width(20)

w.connect("destroy", gtk.main_quit) 

# tabla

tableMin = gtk.Table(3, 2, False)
tableMin.set_border_width(10)

tableMin.set_row_spacings(10)
tableMin.set_col_spacings(8)

lBegin = gtk.Label("Este proceso generara imagenes adecuadas\npara usar de salvapantallas en el Kindle 3.")
tableMin.attach(lBegin, 0, 2, 0, 1)

lName = gtk.Label("Nombre (margen derecho):")
tableMin.attach(lName, 0, 1, 1, 2)

entryName = gtk.Entry()
entryName.set_text("soymicmic")
tableMin.attach(entryName, 1, 3, 1, 2)

cbNomFic = gtk.CheckButton("Incluir nombre de fichero (margen izquierdo).")
cbNomFic.set_active(True);
tableMin.attach(cbNomFic, 0, 2, 2, 3)

# botones

aligBotones = gtk.Alignment(1.0, 0.0)
boxBotones = gtk.HBox(True, 4)

bAceptar = gtk.Button("Aceptar", gtk.STOCK_OK)
bAceptar.connect("clicked", ClickAceptar)
boxBotones.pack_start(bAceptar, False, False, 0)

bCancelar = gtk.Button("Cancelar", gtk.STOCK_CANCEL)
bCancelar.connect("clicked", ClickCancelar)
boxBotones.pack_start(bCancelar, False, False, 0)

aligBotones.add(boxBotones)

tableMin.attach(aligBotones, 1, 2, 4, 5)

w.add(tableMin)
w.show_all()
gtk.main()


Example image attached
Attached Thumbnails
Click image for larger version

Name:	kindle_LW334.png
Views:	936
Size:	363.5 KB
ID:	65580  
Attached Files
File Type: zip To_Kindle.zip (6.8 KB, 332 views)

Last edited by soymicmic; 01-28-2011 at 11:19 AM. Reason: Correct filename with spaces
soymicmic is offline   Reply With Quote
Old 01-27-2011, 06:52 PM   #2
paspas
Enthusiast
paspas began at the beginning.
 
Posts: 29
Karma: 11
Join Date: Jun 2007
Device: prs505
Hola, no me funciona, desde el terminal me dice:

File "/home/paspas/.gnome2/nautilus-scripts/To_Kindle", line 12, in <module>
import Process
ImportError: No module named Process

Se te ocurre que hacer?.
paspas is offline   Reply With Quote
Advert
Old 01-28-2011, 12:33 AM   #3
soymicmic
Junior Member
soymicmic began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Dec 2010
Device: AmazonKindle 3
Quote:
Originally Posted by paspas View Post
Hola, no me funciona, desde el terminal me dice:

File "/home/paspas/.gnome2/nautilus-scripts/To_Kindle", line 12, in <module>
import Process
ImportError: No module named Process

Se te ocurre que hacer?.


Perdón, se me olvido adjuntar los dos ficheros de "Process". Descomprimelos en la misma carpeta
Attached Files
File Type: zip Process.zip (4.9 KB, 308 views)
soymicmic is offline   Reply With Quote
Old 01-28-2011, 09:55 AM   #4
paspas
Enthusiast
paspas began at the beginning.
 
Posts: 29
Karma: 11
Join Date: Jun 2007
Device: prs505
thank you, only fail when in the name you have an space.

----

Gracias, solo falla cuando tienes un espacio en el nombre. Icluye la modificación en ingles para que lo puedan leer los lectores no españoles

Gracias por el curro :P
paspas is offline   Reply With Quote
Old 01-28-2011, 11:20 AM   #5
soymicmic
Junior Member
soymicmic began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Dec 2010
Device: AmazonKindle 3
Quote:
Originally Posted by paspas View Post
thank you, only fail when in the name you have an space.

----

Gracias, solo falla cuando tienes un espacio en el nombre. Icluye la modificación en ingles para que lo puedan leer los lectores no españoles

Gracias por el curro :P
ups... it's ok now, look for the first post.

Thanks

====

Corregido, actualizado en el primer post.

Gracias!
soymicmic is offline   Reply With Quote
Advert
Reply

Tags
screensaver files, script


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to fetch & send to Kindle (Mac/Linux) clanger9 Calibre 5 07-10-2012 05:47 AM
201 Optimzed Screensaver Images Snuggles0220 Amazon Kindle 8 10-29-2010 03:01 PM
Hacks Original screensaver files in Linux file system ? meem Amazon Kindle 4 08-13-2010 07:23 AM
Classic nook screensaver images afa Barnes & Noble NOOK 9 07-20-2010 04:12 PM
Converting PDFs to images (Linux only) kylecronan Kindle Developer's Corner 1 02-28-2009 02:37 PM


All times are GMT -4. The time now is 05:35 AM.


MobileRead.com is a privately owned, operated and funded community.