Accessing a Microsoft Clipart Download from Linux

Written by James McDonald

October 3, 2009

If you go to http://office.microsoft.com/clipart/ Microsoft has a heap of images…

If you read the service agreement you will probably find that you would be better off using services that publish their content via a creative commons license or another open license.

However I digress.

If you are on Linux and you do download an MPF package from the MS clipart site. How do you unpack them?

I tried the Perl utility at http://mpftools.sourceforge.net/ but when trying to open the mpf file I got the following error

./mpfextract.pl ClipArt-jm.mpf 
Not an ARRAY reference at ./mpfextract.pl line 75.

This was caused because the clipart.mpf download only had one image in it…. If you download the clipart.mpf file with more than one image this doesn’t occur:

./mpfextract.pl ClipArt.mpf 
Extracted ./j0442361.jpg
Extracted ./j0442360.jpg
Extracted ./j0442355.jpg

I did code a work-around for the problem. Which involved testing for and changing what was passed into the foreach statement in the mpftools perl script:


my $data = XMLin($mpffile);
# from the line above change it to be as follows
my @ref;

# added this to print the mpf xml to screen
#print Dumper($data->{'D:response'});

# this code checks to see if the return from the $data-> call 
# is a hash ( a single xml node ) or an array (multiple D:response nodes)
if ( $data->{'D:response'} =~ /array/i ) {
	
	@ref = @{$data->{'D:response'}};
	print "It's an Array\n"; 
} else {
	
	print "it's a hash\n";
	@ref = $data->{'D:response'};
}

# so when we go into the foreach the @ref is always an array
# unlike before when it was a hash when it was only 
# a single photo in the mpf
# loop on the files
foreach my $response (@ref) {

If any Perl monk can tell me how to test for an array/hash better than this please comment below.

1 Comment

  1. Luca

    2010-04-28
    Had your same problem with a mpf file with only an image in it, applied your code: everything is working great! Many many thanks!!

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

How to Research a CPU Upgrade

How to Research a CPU Upgrade

Upgrade Time! Doing a lot of VMWare Workstation virtualization to create labs for self-study and training. Finding...