| WebService-Images-Nofrag documentation | Contained in the WebService-Images-Nofrag distribution. |
WebService::Images::Nofrag - upload an image to http://pix.nofrag.com
Version 0.06
my $pix = WebService::Images::Nofrag->new();
$pix->upload({file => '/path/to/the/file'});
# or
$pix->upload({file => '/path/to/the/file'}, '800x600');
# or
$pix->upload({url => 'http://test.com/my/file.jpg', '50%'});
print "URL : " . $pix->url . "\n"; # print the url of the page
print "image : " . $pix->image . "\n";# print the url of the image
print "thumb : " . $pix->thumb . "\n";# print the url of the thumb
upload an image to http://pix.nofrag.com We need a filemane or an URL to an image. You can specify a resolution, so the image will be resized before being uploaded. Set 3 accessors, thumb image & url, with the url to the different data.
Franck Cuny, <franck.cuny at gmail.com>
Please report any bugs or feature requests to
bug-webservice-images-nofrag at rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-Images-Nofrag.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc WebService::Images::Nofrag
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=WebService-Images-Nofrag
Copyright 2006 Franck Cuny, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| WebService-Images-Nofrag documentation | Contained in the WebService-Images-Nofrag distribution. |
package WebService::Images::Nofrag; use warnings; use strict; use Carp; use WWW::Mechanize; use base qw(Class::Accessor::Fast); use Image::Magick; use Image::Magick::Info qw( get_info ); use LWP::Simple; WebService::Images::Nofrag->mk_accessors( qw(thumb image url) );
our $VERSION = '0.06'; our $SITE = 'http://pix.nofrag.com/';
sub upload { my ( $self, $params ) = @_; my $tempory_file = "WIN_temp_file"; if ( !defined $$params{ file } && !defined $$params{ url } ) { croak "Please, give me a file or an url"; } if ( defined $$params{ file } && !-r $$params{ file } ) { croak "Problem, can't read this file"; } if ( defined $$params{ url } ) { getstore( $$params{ url }, $tempory_file ); } # do we need to resize ? if ( defined $$params{ resize } ) { my $img = new Image::Magick; if ( -f $tempory_file ) { $img->Read( $tempory_file ); } else { $img->Read( $$params{ file } ); } $img->Resize( $$params{ resize } ); $img->Write( $tempory_file ); } if ( -f $tempory_file ) { my $info = get_info( $tempory_file, ( "filesize" ) ); if ( $info->{ filesize } > 2000000 ) { croak( "File can't be superior to 2MB" ); } } else { my $info = get_info( $$params{ file }, ( "filesize" ) ); if ( $info->{ filesize } > 2000000 ) { croak( "File can't be superior to 2MB" ); } } $self->{ options } = shift; $self->{ mech } = WWW::Mechanize->new(); $self->{ mech }->get( $SITE ); if ( -f $tempory_file ) { $self->{ mech }->field( 'monimage', $tempory_file ); } else { $self->{ mech }->field( 'monimage', $$params{ file } ); } $self->{ mech }->click_button( input => $self->{ mech }->current_form()->find_input( undef, "submit" ) ); if ( $self->{ mech }->content =~ /Impossible to process this picture!/ ) { $self->url( "none" ); $self->image( "none" ); $self->thumb( "none" ); croak "\tProblem, can't upload this file\n"; } if ( $self->{ mech }->res->is_success ) { my $content = $self->{ mech }->content; $content =~ /\[url=(http:\/\/pix\.nofrag\.com\/.*\.html)\]/; $self->url( $1 ); $content =~ /\[img\](http:\/\/pix\.nofrag\.com\/.*)\[\/img\]/; $self->image( $1 ); my @img = $self->{ mech }->find_all_images(); foreach my $img ( @img ) { last if $self->thumb; if ( $img->url =~ /^$SITE/ ) { $self->thumb( $img->url ); } } } else { croak "Problem, can't upload this file."; } if ( -f $tempory_file ) { unlink $tempory_file; } }
1; __END__