Slideshare.net (beta)

 
Post to TwitterPost to Twitter
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons

All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 4 (more)

Simple Photo Processing and Web Display with Perl

From kcowgill, 8 months ago

I have a small photo gallery on my website and in this presentatio more

3610 views  |  1 comment  |  2 favorites  |  60 downloads
 

Categories

Add Category
 
 

Groups / Events

 
Embed
options

More Info

This slideshow is Public
Total Views: 3610
on Slideshare: 3610
from embeds: 0

Slideshow transcript

Slide 1: Simple Photo Processing and Web Display with Perl Kent Cowgill

Slide 2: Unfortunately, nothing super fancy.

Slide 3: The first camera I used

Slide 4: The pictures were ... ok

Slide 5: The phone stayed in my pocket. Along with pocket lint. A lot of pocket lint.

Slide 6: And a lot of lint got in the lens

Slide 7: And the pictures started in the blurry And a lot of lint got getting lens

Slide 8: Especially with all my daily activities.

Slide 9: Especially with all my daily activities.

Slide 10: And the pictures got blurrier

Slide 11: ... and blurrier ...

Slide 12: And practically unrecognizable.

Slide 13: So I got a new phone.

Slide 14: This has been my camera

Slide 15: The pictures were better

Slide 16: No lint problem, even in harsh conditions

Slide 17: Until my phone dropped out of my pocket and was picked up by Ricardo Signes at YAPC

Slide 18: But that blurriness was user error.

Slide 19: Thankfully, he returned my phone to me.

Slide 20: What a nice guy.

Slide 21: My RAZR has served me well.

Slide 22: Until Recently

Slide 23: More on that later.

Slide 24: Step 1: Get the picture from the phone to the server.

Slide 25: This is what I looked like

Slide 26: Taking pictures with my RAZR

Slide 27: The obligatory cat

Slide 34: www.kentcowgill.org

Slide 35: Step 2: Get the picture from the email to the filesystem.

Slide 36: strip image from mail cowgill motorola v551 2/9/05 1

Slide 37: use MIME::Parser; use MIME::Entity; use MIME::Base64 qw(decode_base64); use Image::Magick::Thumbnail;

Slide 38: my $parser = MIME::Parser->new(); $parser->output_dir( '/www/kentcowgill/photos/data' ); my $message = $parser->parse( \\*STDIN ) };

Slide 39: DFS? for my $part( $message->parts_DFS ){ if( $part->bodyhandle ){ if( $part->mime_type eq 'image/jpeg' ){ $filename = $part->bodyhandle->path; $data .= $part->as_string; $data =~ s/.*\\n\\n(.*)/$1/ms; } Ew. $data = decode_base64($data); ...

Slide 40: ... open ARCHIVE, '>', $archive_image; binmode ARCHIVE; Error checking print ARCHIVE $data; is left as an exercise close ARCHIVE; for the reader. my $src = new Image::Magick; $src->Read($archive_image); ...

Slide 41: ... my( $thumb, $x, $y ) =Image::Magick::Thumbnail::create( $src, 64 ); $thumb->Write($archive_thumb); } }

Slide 42: Worked great.

Slide 43: Flawlessly.

Slide 44: For a while.

Slide 45: Until I upgraded... Perl Image::Magick And with all their dependencies... God only knows what else.

Slide 46: WTF?

Slide 47: Then something broke. WTF?

Slide 48: It didn't make thisbroke. Then something blurry. WTF?

Slide 49: No, thatsomething broke. Then make this blurry. It didn'twas poor technique. WTF?

Slide 50: No, thatsomethingmy photos. It started make off broke. Then cutting this blurry. It didn'twas poor technique. WTF?

Slide 51: It was really annoying. WTF?

Slide 52: And inconsistent. WTF?

Slide 53: Cockroaches Termites (Not to scale) Bunnies (Also not to scale)

Slide 54: Tough to reliably reproduce.

Slide 55: So I spent my time and energy elsewhere.

Slide 56: Step 3: Get the picture from the filesystem to the web browser.

Slide 57: This is the site that I made

Slide 58: To view the pictures that I took

Slide 59: Click on a thumbnail...

Slide 60: And see the full image.

Slide 61: But not that one. ;-)

Slide 62: <?php $start = $_GET[\"start\"] ? $_GET[\"start\"] : \"0\"; $filearray = array(); $dir = \"/www/kentcowgill/photos/arch\"; $mydir = \"/photos/arch\"; $thumbdir = \"/photos/thumbs\"; if( $handle = opendir( $dir ) ){ while( false !== ( $file = readdir( $handle ) ) ){ if( $file != \".\" && $file != \"..\"){ array_push( $filearray, $file ); } } closedir( $handle ); } ...

Slide 63: PHP?

Slide 64: Didn't I say Perl at the beginning?

Slide 66: $_ == 0 && do { $table .= \"<tr><td align=center height=$CELLHEIGHT \" . \"width=$CELLWIDTH valign=bottom>\"; last SWITCH; }

Slide 67: $_ == 0 && do { $table .= \"<tr><td align=center height=$CELLHEIGHT \" . \"width=$CELLWIDTH valign=bottom>\"; last SWITCH; } My only excuse is that I wrote it a really long time ago

Slide 68: :-p~

Slide 73: The picture viewer was updated as well.

Slide 74: I also got a dog. Cat Dog

Slide 75: And I stored the users' preferences...

Slide 76: User Preferences

Slide 77: Step 4: Fix the image stripping bug.

Slide 78: strip image from mail cowgill motorola RAZR v3 7/25/06 2

Slide 79: Add module version requirements.

Slide 80: use MIME::Parser; use MIME::Entity; use MIME::Base64 qw(decode_base64); use Image::Magick::Thumbnail;

Slide 81: use MIME::Parser 5.415; use MIME::Entity 5.415; use MIME::Base64 3.07 qw(decode_base64); use Image::Magick::Thumbnail;

Slide 82: Add debugging and logging.

Slide 83: my $parser = MIME::Parser->new(); $parser->output_dir( '/www/kentcowgill/photos/data' ); my $message = $parser->parse( \\*STDIN ) };

Slide 84: my $parser = MIME::Parser->new(); $parser->output_to_core(1); $parser->output_dir( '/www