Bonjour à tous;
J'ai retrouvé un script modifié avec Didier-T, permettant de télécharger une image au hasard sur le site de la nasa. Celui-ci fonctionne très bien mais j'aimerais ajouter une fonction de redimmentionement de l'image téléchargée dedans...
ce genre de fonction :
if [ -f $tmp ] ; then # si le fichier a bien été téléchargée...
mogrify -resize 800x600 $tmp # redimenssionne l'image téléchargée
mv $tmp $img # remplace l'ancienne image par la nouvelle
fi
Le problème c'est que le script initial est en perl :/ :
randpixnasa.pl:
#!/usr/bin/perl
# Copyright (c) Laszlo Simon.
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or ( at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA)
# CONFIGURATION
##$explonation = 'true'; # true | false
##$explonation_place = 'south'; # east|north|west|south|norteast|...
# INIT
use LWP::Simple;
$repsauv = "~/wallpapers";
if (`xdpyinfo | grep dimensions` =~ /(\d+)x(\d+)\s+pixels/)
{
($width, $height) = ($1,$2);
}
else
{
die("Can not determine screen resolution. Maybe 'xdpyinfo' not installed.\n");
}
$explonation_width = int($width * 2 / 3);
$explonation_height = int($width / 10);
#if (system("wget --version"))
#{
# die("'wget' should be installed.\n")
#}
for ($i=1; $i<=10; $i++)
{
$date = sprintf("%02d",0+int(rand(8)))
.sprintf("%02d",1+int(rand(12)))
.sprintf("%02d",1+int(rand(28)));
$content = get("http://antwrp.gsfc.nasa.gov/apod/ap$date.html" );
$content =~ /\<a\s+href\=\"((?:\w+\/)*)(\w+)(\.\w+)\"\s*\>\s*\n*\s*\<img/ims;
$path = $1;
$img = $2;
$ext = $3;
if ($ext eq ".jpg")
{
last;
}
}
my $home = $ENV{'HOME'};
$repsauv =~ s/~/$home/;
if (!-e "$repsauv")
{
mkdir ("$repsauv");
}
print ">>>>http://antwrp.gsfc.nasa.gov/$path$img$ext\n";
my $imag = get("http://antwrp.gsfc.nasa.gov/$path$img$ext");
open(SORTIE, ">$repsauv/image$ext");
binmode(SORTIE);
print SORTIE $imag;
close(SORTIE);
#system("wget -q -O ~/wallpapers/$img$ext 'http://antwrp.gsfc.nasa.gov/$path$img$ext'");
# Get text
#if (system("html2text -version"))
#{
# warn("Explonation disabled. 'html2text' should be installed.\n");
# $explonation = 'false';
#}
#if (system("convert -version"))
#{
# warn("Explonation disabled. 'convert' (imagemagick) should be installed. \n");
# $explonation = 'false';
#}
#if ($explonation eq 'true')
#{
# system("html2text -style pretty -o /tmp/apxxxxxx.txt /tmp/apxxxxxx.html");
# open TXT, "/tmp/apxxxxxx.txt";
# $content = join('',(<TXT>));
# close TXT;
# $text =
# ($content =~ /Explanation:\s*(.*)\s*Tomorrow\'s picture:/s)
# ? $1
# : '';
# print $text."\n";
# $text =~ s/\n/ /g;
# open TXT, ">/tmp/apxxxxxx-anno.txt";
# print TXT $text;
# close TXT;
# system("convert ~/wallpapers/$img$ext "
# ."-resize $width"."x$height\\> "
# ."-size $width"."x$height xc:black +swap "
# ."-gravity center "
# ."-composite "
# ."~/wallpapers/$img$ext"
# );
# system("convert "
# ."-background '#0008' "
# ."-fill white "
# ."-gravity north "
# ."-pointsize 20 "
# ."-size $explonation_width"."x$explonation_height "
# ."caption:\@/tmp/apxxxxxx-anno.txt "
# ."~/wallpapers/$img$ext "
# ."+swap -gravity $explonation_place -composite "
# ."~/wallpapers/$img$ext"
# );
#}
#system("mv ~/wallpapers/$img$ext ~/wallpapers/image.jpg");
Merci d'avance pour un ptit coup de main 😉
EDIT: Il faudrait peut-être que l'image téléchargée soit modifiée avec un % car elle ne fait jamais la même taille. Le but est de pouvoir l'afficher correctement dans un conky...
genre:
convert ~/wallpapers/image.jpg -resize 40% ~/wallpapers/image.jpg