Jump to content

Recommended Posts

Posted (edited)

Hey guys, I am having trouble with a perl script that I downloaded. This is the first perl I have tried to use so bare with me. I have it installed in a folder called /scripts

 

the name of the script is "mt_image_gallery.pl"

I got it here

 

My problem is that everytime I run it (which Im not sure Im doing correctly) I get a Internal server error 500

I am running it by just opening my browser and entering www.mysite.com/scripts/mt_image_gallery.pl

 

I checked my error log in cpanel and found that the error is " Premature end of script headers:"

hope that helps someone :(

 

 

It is supposed to help import photos as entries into Movable Type for use with Doug Bowmans gallery templates. I have tried using Picasa to export galleries with a custom export template and have had no luck. If anyone has a better Idea please let me know! Thanks in advance

 

 

here is the script.

 

 

>#!/usr/bin/perl

# -------------------------------------------------------------------- #
# Name:		Export Photos to Movable Type (mt_image_gallery.pl_
#
# Function: This script will resize the photos in the directory of your
#		choice into two sizes: 480x360 (large) and 90x68 (small).
#		Furthermore, the script will automatically create entries
#		for those images into the blog of your choice. This 
#		works with Stopdesign.com's Photo Gallery Templates.
#
# Notes:	Remember that your pictures will need to be in 1024x768, 
#		1600x1200, or 2272x1704 dimensions. The templates are 
#		created for images with those dimensions or images 
#		equivalent to the 4:3 ratio.
#
#		See http://stopdesign.com/templates/photos/
#
# Author:   Emil Soleyman-Zomalan <emil@nishra.com>
#
# Bugs:		I know that the script has bugs and needs some TLC. I would
#		appreciate any reports or patches towards improving its 
#		functionality and usefulness.
#	   
#		TBD	* Encrypt the password to hide from memory
#		* Do more error checking along each step
#		* Look to resizing the images quicker
#		* Make a plugin out this
#
# License:  Creative Commons's Attribution-NonCommercial-ShareAlike 2.5
#
# Version:  0.3
# -------------------------------------------------------------------- #

use Net::MovableType;
use File::Basename;
use File::Find::Rule::Type;
use Term::ReadLine; # Term::ReadLine::Gnu
use Image::Magick;
use strict;

my ($photos_url, $photos_loc, $location, $category, $username, $password);
my ($domain, $xmlrpc, $blog_id, $mt);

# ----------------------------
# CONFIGURATION
# ----------------------------
$domain		= '';   # The complete domain name including http://
$category   = '';   # The title of the gallery/category
$photos_url = '';   # The relative URL to the photos top-level directory
$photos_loc = '';   # The file location of the photos templates
$location   = '';   # The location of the image files
$username   = '';   # The Movable Type username
$password   = '';   # API password (important!)
$xmlrpc		= '';   # The URL of the XML-RPC file
$blog_id	= '';   # The blog ID of the photo blog


# ----------------------------
# MAIN
# ----------------------------

# Begin interview process
usage();
ask_questions();

# Login to MovableType
$mt = login_to_mt();

# Create gallery through use of category function
populate_gallery();

# Resize image files into large and small dimensions
# Large: 480x360, Small: 90x68
resize_image_files();


# ----------------------------
# SUBROUTINES
# ----------------------------

sub usage {
print "\nUsage: $0\n\n";
print "The function of this script is to insert entries into the " .
  "Movable Type blog \nof your choice containing " .
	  "Stopdesign.com's Photo Gallery " .
  "Templates.\n\n";
print "......................................................." .
	  "....................\n\n";
}

sub ask_questions {
my ($term, $attribs, $prompt_domain, $prompt_cat, $prompt_photos_url);
my ($prompt_photos_loc, $prompt_loc, $prompt_user, $prompt_pass);
my ($prompt_xmlrpc, $prompt_blog_id);

$term = new Term::ReadLine 'mt_image_gallery';
$attribs = $term->Attribs;

# Prompt for category (gallery) name
if (!$category) {
print "[ Gallery Title ]\n";
print "NOTE: You must create a top-level category within Movable Type\n" .
	  "first. Then cut-and-paste the name in this section.\n";
$prompt_cat = ": ";
	$category = $term->readline ($prompt_cat);
}

# Prompt for domain name
if (!$domain) {
print "\n[ Domain Name ]\n";
print "e.g http://www.domain.com\n";
$prompt_domain = ": ";
$domain = $term->readline ($prompt_domain);
}

# Prompt for photo template URL location
if (!$photos_url) {
print "\n[ Relative URL of Photo Templates ]\n";
print "e.g /photos/ as in http://www.domain.com/photos/\n";
$prompt_photos_url = ": ";
$photos_url = $term->readline ($prompt_photos_url);
}

# Prompt for photo template file location
if (!$photos_loc) {
print "\n[ File location of Photo Templates ]\n";
print "e.g /var/www/domain.com/photos \n";
$prompt_photos_loc = ": ";
$photos_loc = $term->readline ($prompt_photos_loc);
}

# Prompt for image location on the hard drive
if (!$location) {
print "\n[ Image File Location ]\n";
print "e.g /home/user/gallery/sample-photos\n";
$prompt_loc = ": "; 
$location = $term->readline ($prompt_loc);
}

# Prompt for username
if (!$username) {
print "\n[ Blog Username ]\n";
$prompt_user = ": ";
$username = $term->readline ($prompt_user);
}

# Prompt for API password
if (!$password) { 
print "\n[ API Password ]\n";
$prompt_pass = ": ";
$attribs->{redisplay_function} = $attribs->{shadow_redisplay};
$password = $term->readline ($prompt_pass);
undef $attribs->{redisplay_function};
}

# Prompt for xmlrpc location
if (!$xmlrpc) {
print "\n[ URL of XML-RPC file ]\n";
$prompt_xmlrpc = ": ";
$xmlrpc = $term->readline ($prompt_xmlrpc);
}

# Prompt for blog id
if (!$blog_id) {
print "\n[ Photo Blog ID ]\n";
$prompt_blog_id = ": ";
$blog_id = $term->readline ($prompt_blog_id);
}

print "\n......................................................." .
	  "....................\n\n";
}

sub login_to_mt {
my ($mt);

$mt = new Net::MovableType("$xmlrpc");
$mt->username("$username");
$mt->password("$password"); # API password; see release notes
$mt->blogId("$blog_id");

return ($mt);
}

sub populate_gallery {
my ($temp_entry, $temp_id);

# We prime the category so that all of the files and subdirectories
# needed by the gallery templates have been created.
$temp_entry = {
title		=> "test title",
description => "test description"
};

$temp_id = $mt->newPost ($temp_entry, 0) or die $mt->errstr;	
$mt->setPostCategories ($temp_id, "$category");
$mt->publishPost ($temp_id);
$mt->deletePost($temp_id);	# Delete the bogus post now
}

sub resize_image_files {
my (@images, $image, $temp);
my ($name, $path, $suffix);
my ($large_name, $small_name, $gallery);
my ($entry, $new_id);
my ($counter);

# Convert category/gallery title to lowercase and replace 
# whitespace with dashes. This is the same way that the gallery
# name is created for the first time.
$gallery = lc ($category);
$gallery =~ s/ /-/g;
$gallery = $gallery . "/gallery/";	# <gallery_title>/gallery/

@images = find ( file => type => 'image/*', in => "$location" );

if (scalar(@images) < 1) {
print "WARNING: The application cannot find images at" . 
	  "$location. Please check that location and try again.\n";
exit;
} else {	
print "Images are being created in $photos_loc" . "$gallery\n\n";

	$counter = 1;	
foreach (@images) {	
	($name, $path, $suffix) = fileparse ($_, '\.[^.]*');

	# Initialize ImageMagick
	$image = Image::Magick->new;

	# Read image
	$temp = $image->Read ($_);
	warn "$temp" if "$temp";
	
	# Create large dimension image
	$large_name = "$name" . "_large" . "$suffix";
	$temp = $image->Resize (geometry=>"480x360");
	$temp = $image->Write ("$photos_loc" . "$gallery" . "$large_name");

	# Create small dimension image
	$small_name = "$name" . "_small" . "$suffix";
	$temp = $image->Resize (geometry=>"90x68");
	$temp = $image->Write ("$photos_loc" . "$gallery" . "$small_name");

	print "* $name$suffix resized ";
	
	# Add an entry for each image
	$entry = {
	title		=> "$category - $counter",
	description	=> "<img alt='' title='' src='" . "$domain" . "$photos_url" . "$gallery" . "$large_name" . "' width='480' height='360' />",
	mt_text_more	=> "<img alt='' title='' src='" . "$domain" . "$photos_url" . "$gallery" . "$small_name" . "' width='90' height='68' />",
	};

	$new_id = $mt->newPost ($entry, 0) or die $mt->errstr;  
	$mt->setPostCategories ($new_id, "$category");
	$mt->publishPost ($new_id);

	print "& entry created\n";
	
	$counter++;
}
}
}

Edited by evhwanabe
Posted
My problem is that everytime I run it (which Im not sure Im doing correctly) I get a Internal server error 500

I am running it by just opening my browser and entering www.mysite.com/scripts/mt_image_gallery.pl

 

For starters, this script will only work from a command line, not through as a CGI using a browser to access it, which pretty much rules using this script on your shared hosting account right there. The script would have to be rewritten to make it work in a browser.

 

Secondly...

 

>use Net::MovableType;  <----
use File::Basename;
use File::Find::Rule::Type; <----
use Term::ReadLine; # Term::ReadLine::Gnu
use Image::Magick;
use strict;

 

It requires modules (the two above and some supporting modules) that are likely not installed on the TCH servers which is the other reason the script fails. But like I said, it's a command line script, not a brower accessible script, so it won't do you any good even if the modules are installed.

 

You'll be better off finding something that is designed for browser access.

Posted
For starters, this script will only work from a command line, not through as a CGI using a browser to access it, which pretty much rules using this script on your shared hosting account right there. The script would have to be rewritten to make it work in a browser.

 

Secondly...

 

>use Net::MovableType;  <----
use File::Basename;
use File::Find::Rule::Type; <----
use Term::ReadLine; # Term::ReadLine::Gnu
use Image::Magick;
use strict;

 

It requires modules (the two above and some supporting modules) that are likely not installed on the TCH servers which is the other reason the script fails. But like I said, it's a command line script, not a brower accessible script, so it won't do you any good even if the modules are installed.

 

You'll be better off finding something that is designed for browser access.

 

Ok thanks Mike, I will keep looking.

 

The person that developed the script didn't really have any documentation and I am new to perl scripts.

Posted
Ok thanks Mike, I will keep looking.

 

The person that developed the script didn't really have any documentation and I am new to perl scripts.

 

The author mentioned making it a plug-in at some point, so you may want to bookmark his page at least. Maybe he'll eventually modify it to work via a browser.

Posted
The author mentioned making it a plug-in at some point, so you may want to bookmark his page at least. Maybe he'll eventually modify it to work via a browser.

 

 

I went back and took another look at my picasa export templates, and ended up finding a stupid error on my part, and got it working in a couple minutes lol. If anyone would like these templates let me know. They are not perfect but seem to atleast get the entries into movable type.

 

Thanks!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...