domingo, 3 de octubre de 2010

Galería de fotos de Picasa

Aquí está el código que he utilizado para poder insertar una galería de fotos pública de Picasa en una web. Se puede mejorar en cuanto al formato de presentación de las fotos, y la función de llamada para mostrar las mismas (que no incluyo porque es solamente añadir una etiqueta <img> con la imagen que se pasa por parámetro).

Intenté hacerla con la librería de Perl XML::RSS pero era imposible ya que no era capaz de acceder a las etiquetas de las fotos.

Por otro lado, algo que quizá se pueda entender poco del código, es en la formación de la variable $imagen. Mirando el código XML del RSS del álbum de Picasa se puede ver que existen unas versiones en miniatura de las imágenes en la dirección "Carpeta_de_la_foto/s144/Nombre_de_la_foto" donde también están las carpetas "s72" y "s288" dependiendo de la altura de dicha miniatura.

Si quieres saber qué me ha llevado a hacerla, lee la entrada sobre lo mismo de mi otro blog.
#!/usr/bin/perl

use CGI qw(:standard);
use XML::Simple;
use LWP::Simple qw(get);

my $direccion = "Dirección web del RSS del álbum de picasa";

#Baja  fichero
 my $rdf = get($direccion);
 my $xml = XML::Simple->new();
 my $doc = $xml->XMLin($rdf);

 my $numero_elementos = $doc->{channel}->{'openSearch:totalResults'};

 my $salida = '<body style="text-align:justify;"> ';

 print header( -type => 'text/html', -charset => 'iso-8859-1' );

 for (my $i = 0; $i < $numero_elementos; $i++){
  my $dir = $doc->{channel}->{item}[$i]->{enclosure}->{url};
  my @ruta = split('/',$dir);
  my $imagen = substr($dir,0,index($dir,$ruta[-1]));
  $imagen .= 's144/'.$ruta[-1];
  $salida .= '<a href="javascript:parent.mostrarFoto( \''.$dir.'\' )" style="text-decoration:none;"><img height=70px src="'.$imagen.'" /></a>  ';
 }

 $salida = $salida.'</body>';
 print $salida;

1 comentario:

  1. This is all of the more cause to grasp the home benefit and method it} works towards a player who has lost a big sum and 우리카지노 is spending lots of time in the casino making an attempt to win it again. The more a player struggles to get ahead, the more they get pulled into additional losses. You can contact the help staff by way of the Help section. Players are first directed to an FAQ library, which is fairly detailed and loaded with info on online slot video games. You would possibly know Ignition as one of the best spot for online poker, however if you have a look beneath the surface, this online playing web site has so much to offer in the slot game division. You'll get pleasure from high RTP titles and a $3,000 welcome bonus to start out|to begin} your journey at Ignition.

    ResponderEliminar