File Paths under PerlMagick for Windows
Part of Dylan's Collection of PerlMagick Stuff
Under Windows, Perl uses the forward-slash as the path delimiter - so if you're passing paths in from other Windows languages, you need to substitute / for \ in the path definitions. (Think about it - \ is an escape character in Perl, so c:\new\names\ is actually a three-line string :)) Perl paths should look like c:/myfolder/myfile.jpg, and relative paths should be relative to the directory from which the script is *executing* - NOT the folder where the script is actually stored (they can be different). Regarding absolute vs. relative paths, one of the 'quirks' of IIS is that scripts don't execute from the path they're stored in. Try the following short snippet of code:
#!/bin/perl use Cwd; print "Content-type: text/html\r\n\r\n"; print cwd();
If you run this from c:\inetpub\wwwroot\cgi-bin\, it'll print "c:\inetpub\wwwroot" as the current working directory. If you run it from c:\inetpub\wwwroot\cgi-bin\my\sub\folder\ it'll *still* print "c:\inetpub\wwwroot" as the current working directory.
Much of what I do involves calling PerlMagick scripts from ASP pages - the ASP page will contain a tag something like:
<img src="/cgi-bin/resize.pl?src=<%=some_image%>&width=200&height=200" width="200" height="200">
(For those not familiar with ASP syntax, within this code, the <%=some_image%> will expand at runtime the the value of the variable some_image.)
Somewhere higher up the page, I'll put in a call like:
some_image = Server.URLEncode(Replace(Server.MapPath("/images/myimage.jpg"), "\", "/")
In this, the .MapPath method will turn the WWW relative path (/images/myimage.jpg) into an absolute path on the local filesystem (c:\inetpub\wwwroot\mysite\images\myimage.jpg). The Replace call will perform the slash-substitution (c:/inetpub/wwwroot/mysite/images/myimage.jpg) and the URLEncode method will encode this path so it can be safely passed via the QueryString - producing
This way, the ASP code (which has access to the Server object) performs all the complicated substitution, and the path that's passed to resize.pl is already in the correct format.
Page maintained by Dylan Beattie. <imagemagick [at] dylanbeattie [dot] net>
Copyright © 2001 dylanbeattie.net.
The information contained in this page may be freely distributed and modified
subject to the terms of the ImageMagick distribution agreement.