Image-Randim

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

commit a237670876b24cf04928e78b67ab851a30580a7e
Author: Mark Rushing <mark@orbislumen.net>
Date:   Sun Sep 23 13:27:29 2018 -0700

    Version bump

commit e3f6711e02642748e7567ce768d90a05a87e00ae
Author: Mark Rushing <mark@orbislumen.net>
Date:   Sun Sep 23 13:17:38 2018 -0700

    default image viewer is now 'feh' and fallback to 'eog'. gnome3 desktop wallpaper is taken from the main directory now rather than the directory you saved the desktop image to.

commit 0eca0d9dd43f2d8534403d92c66c7be21f0830df
Author: Mark Rushing <mark@orbislumen.net>
Date:   Sun Sep 23 12:42:54 2018 -0700

    Added .gitignore file. 'randim' script will use default viewer unless setting desktop background with --gnome3 swtch

commit 961a14d2a0b6730ddf8aeffa0dc7e6eea05c602d
Author: Mark Rushing <mark@orbislumen.net>
Date:   Wed Sep 13 13:13:30 2017 -0700

    Added some documentation for a desktop icon

commit 18a86a7ec9cbc4bc3689957245ff5b87854b3bb2
Author: Mark Rushing <mark@orbislumen.net>
Date:   Mon Sep 4 07:59:48 2017 -0700

    Image information text is now saved along with the image file to provide artist credit

commit a7f482e17b671dfa86f65e02df1bf49e59e15235
Author: Mark Rushing <mark@orbislumen.net>
Date:   Sun Sep 3 18:53:24 2017 -0700

README  view on Meta::CPAN

Image::Randim::Source provides a quick way to pull information about
random image from an online image provider, such as Desktoppr or
Unsplash.

It was created to make it easy to look at many different random images
for desktop wallpaper switching.

The library provides a means to pull just the necessary information to
get the image URLs, but does not provide the download capability.

The included script "randim" does provide that ability, though, along
with ways to store images you like locally and change the desktop
background.

The module can easily be expanded to support additional online sources
by creating a module that implements Image::Randim::Source::Role and
I'd love to add some more.

POD documentation is included with each module and the script.

lib/Image/Randim/Source/Role.pm  view on Meta::CPAN


  package Image::Randim::Source::Desktoppr
  use Moose;

  has 'name' => ( is  => 'ro',
		  isa => 'Str',
		  default => 'Desktoppr',
      );
  has 'url' => ( is  => 'ro',
		 isa => 'Str',
		 default => 'https://api.desktoppr.co/1/wallpapers/random',
      );

  with 'Image::Randim::Source::Role';

  sub get_image {
      my $self = shift;
      my $data = JSON->new->decode($self->get_response);
      $data = $$data{'response'};

      my $image = Image::Randim::Image->new(

script/randim  view on Meta::CPAN

        remove_tree($output_dir, {keep_root => 1});
    }
    copy($temp->filename, $output_dir.$filename);
    open INFOFILE, ">$output_dir$filename.txt";
    print INFOFILE $info_text;
    close INFOFILE;
    if ($delete_after && !$no_delete) {
        remove_files($output_dir, $filename);
    }

    ## Set the desktop background OR view it with a viewer
    ##
    if ($gnome3) {
        `gsettings set org.gnome.desktop.background picture-uri "file:///$output_dir$filename"`;
    } else {
        system("$viewer $output_dir$filename &");
    }

    unless ($no_prompt) {
	my $saveit = prompt("Do you want to save this image locally?", -yesno, -single);
	if ($saveit) {
	    say "saving $filename to $save_to_dir";
	    copy($output_dir.$filename, $save_to_dir);
	    copy($output_dir.$filename.'.txt', $save_to_dir);

script/randim  view on Meta::CPAN

--save-to-dir <dir> (default: $save_to_dir)
    Directory where images can be "permanently saved".

--timeout <seconds> (default: $req_timeout)
    How many whole seconds to wait for each Internet request to
    respond.

--no-prompt
    Just grab a random image and exit.
--gnome3
    Set the desktop background to the image in Gnome3

--viewer [<program>] (defaults: feh and eog)
    Display image in default viewer or the one specified.

--unsplash-key <key>
    Unsplash requires a so-called developer key. The default one is
    the author's, but they can become rate-limited. If you find that's
    the case for your use, you can register for your own developer
    client key and enter it here.

script/randim  view on Meta::CPAN


=pod

=head1 NAME

randim - Download a random image from online sources

=head1 SYNOPSIS

  # Default, radim deletes all files in $HOME/Pictures/Desktop-Randim
  # and downloads a random image to that directory. Good for desktop
  # environments that can watch a directory for changes.
  $ randim

  # You can have it set the desktop wallpaper in gnome shell
  $ randim --gnome3

  # Maybe you want to view it in a viewer? Specify the executable with
  # this, or leave it blank for eog
  $ randim --viewer
  $ randim --viewer gwenview

  # Only want to pull from Desktoppr?
  $ randim --source Desktoppr

script/randim  view on Meta::CPAN

  # Just grab a random image and exit
  $ randim --no-prompt

  # Unsplash is rate limiting - I'll enter my own API key
  $ randim --unsplash-key 00023fd8ae25887....

=head1 DESCRIPTION

Script using the Perl Image::Randim::Source library to pull random
images down that people have given out to the world on various
websites. This was written for getting new desktop images, and it's
always wonderful seeing what other people are creating and sharing for
us. :)

Without any options, the program loops continuously after each
downloaded image, asking if you want to keep it. So you can just let
chance let you stumble on something you like.

It downloads to your home directory by default, into your Pictures
folder, into a subdirectory there called Desktop-Randim. This
directory gets cleaned out on every single loop so never put anything
important there. Of course you can change this behavior.

This is done, for example, because some desktop environments you can
set wallpaper changing to watch a directory for files. Just have it
watch this directory, and when you download a new image, it will show
up as your background, and keep on looping through until you find one
you want to keep.

Gnome3 in its forever downward spiral into assuming the dumbest users
possible, doesn't let you do something like this, but you can specify
--gnome3 and it will set your background for you on each loop
iteration.

For me, I just needed something that didn't rely on any one particular
desktop environment's plugins to do, since I change environments
frequently.

=head1 ARGUMENTS

  --list-sources
      List supported sources by installed plugins.
  --show-url
      Show the image URL in the info display.
  --source <name>
      By default all sources are used. Specify --source multiple times

script/randim  view on Meta::CPAN

  --save-to-dir <dir> (default: $HOME/Pictures/Desktop-Saved/)
      Directory where images can be "permanently saved".

  --timeout <seconds> (default: 20)
      How many whole seconds to wait for each Internet request to
      respond.

  --no-prompt
      Just grab a random image and exit.
  --gnome3
      Set the desktop background to the image in Gnome3

  --viewer [<program>] (default: eog)
      Display image in default viewer or the one specified.

  --unsplash-key <key>
      Unsplash requires a so-called developer key. The default one is
      the author's, but they can become rate-limited. If you find that's
      the case for your use, you can register for your own developer
      client key and enter it here.

  --version
      Print the version.

=head1 EXAMPLES

I use an icon on a Debian Stretch Cinnamon Desktop to click and walk
through random desktops until I find one I like. You just put a file
called randim.desktop in your home directory's Desktop folder - and it
contains this:

  [Desktop Entry]
  Name=Randim
  Exec=randim --gnome3
  Type=Application
  Categories=AudioVideo
  Comment=Change desktop to a random image
  Encoding=UTF-8
  Icon=image
  Terminal=true

=head1 AUTHOR

Mark Rushing <mark@orbislumen.net>

=head1 COPYRIGHT AND LICENSE

t/001-initial.t  view on Meta::CPAN

can_ok $image, 'id';
can_ok $image, 'width';
can_ok $image, 'height';
can_ok $image, 'url';
can_ok $image, 'filename';
can_ok $image, 'owner';
can_ok $image, 'link';

## Test Image::Randim::Source::Desktoppr
##
#ok my $desktoppr = Image::Randim::Source::Desktoppr->new, 'Image::Randim::Source::Desktoppr instantiates';
#can_ok $desktoppr, 'name';
#can_ok $desktoppr, 'url';
#can_ok $desktoppr, 'get_image';
#can_ok $desktoppr, 'timeout';
#is $desktoppr->name, 'Desktoppr', 'Correct Desktoppr name';
#like $desktoppr->url, qr!^https://api.desktoppr.co!, 'Desktoppr API URL';

## Test Image::Randim::Source::Unsplash
##
ok my $unsplash = Image::Randim::Source::Unsplash->new, 'Image::Randim::Source::Unsplash instantiates';
can_ok $unsplash, 'name';
can_ok $unsplash, 'url';
can_ok $unsplash, 'get_image';
can_ok $unsplash, 'timeout';
can_ok $unsplash, 'api_key';
is $unsplash->name, 'Unsplash', 'Correct Unsplash name';



( run in 0.440 second using v1.01-cache-2.11-cpan-299005ec8e3 )