#!/usr/bin/perl -I/home/alanpenn/www/cgi-bin/lib use MT; use MT::Blog; use MT::Entry; use MT::Placement; use MIME::Parser; use File::Copy; sub create_entry($$$) { my ($title, $body, $path) = @_; my $rotate = 0; if ($body =~ /ROTATE90/) { $rotate = 1; $body =~ s/ROTATE90//s; } my $mt = MT->new; my $entry = MT::Entry->new; $entry->blog_id(2); $entry->status(MT::Entry::RELEASE()); $entry->author_id(1); $entry->allow_comments(1); $entry->convert_breaks(1); $entry->title($title); $entry->text($body); $entry->category(8); $entry->save or die $entry->errstr; $newbody = "

$body"; copy($path, "/home/alanpenn/www/photoblog/images/000".$entry->id.".jpg"); $mode = 0644; chmod $mode, "/home/alanpenn/www/photoblog/images/000".$entry->id.".jpg"; $entry->text($newbody); $entry->save or die $entry->errstr; my $place = MT::Placement->new; $place->entry_id($entry->id); $place->blog_id($entry->blog_id); $place->category_id(8); $place->is_primary(1); $place->save or die $place->errstr; $entry->save or die $entry->errstr; $filename = "/home/alanpenn/www/photoblog/images/000".$entry->id.".jpg"; $thumb = "/home/alanpenn/www/photoblog/images/thumbs/000".$entry->id.".jpg"; $data = `/usr/bin/imgsize $filename`; # print STDERR $data; $w = $data; $h = $data; $w =~ s/.*width=\"(.*?)\".*/$1/s; $h =~ s/.*height=\"(.*?)\".*/$1/s; # print STDERR "$w $h"; #thumbnail image $thumb_w = 125; $thumb_h = ($thumb_w * $h)/$w; $command = "/usr/local/bin/convert $filename -scale $thumb_w"."x"."$thumb_h $thumb"; `$command`; if ($rotate) { $command = "/usr/local/bin/convert $thumb -rotate 90 $thumb"; `$command`; } #resize image if it's too big if ($w > 600) { $post_w = 600; $post_h = ($post_w * $h)/$w; $command = "/usr/local/bin/convert $filename -scale $post_w"."x"."$post_h $filename"; `$command`; } if ($rotate) { $command = "/usr/local/bin/convert $filename -rotate 90 $filename"; `$command`; } $mode = 0644; chmod $mode, $thumb; $mode = 0644; chmod $mode, $filename; #rebuild # my $blog = MT::Blog->load($entry->blog_id); # $mt->rebuild_entry(Entry => $entry, BuildDependencies => true) or die $mt->errstr; } chdir("/home/alanpenn/www/cgi-bin"); $title = $ARGV[0]; $bodytext = ""; ### Create parser, and set some parsing options: my $parser = new MIME::Parser; $parser->output_under("/tmp"); ### Parse input: $entity = $parser->parse(\*STDIN) or die "parse failed\n"; ### Take a look at the top-level entity (and any parts it has): $num = $entity->parts; for ($i = 0; $i < $num; $i++) { $part = $entity->parts($i); $type = $part->effective_type; if ($type eq "image/jpeg") { $body = $part->bodyhandle; if ($body && $body->path =~ /\.jpg/i) { $orig_name = $body->path; $orig_name =~ s/.*\/(.*?\.jpg).*/$1/si; $orig_name =~ s/ /_/gs; $path = $body->path; } } if ($type eq "text/plain") { $body = $part->bodyhandle; $bodytext .= $body->as_string; } } create_entry($title, $bodytext, $path); for ($i = 0; $i < $num; $i++) { $part = $entity->parts($i); $body = $part->bodyhandle; $body->purge(); }