Problem with unix subdirectory relative path as input file..

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
perhapsyes
Posts: 2
Joined: 2013-09-28T20:00:06-07:00
Authentication code: 6789

Problem with unix subdirectory relative path as input file..

Post by perhapsyes »

I have been having some trouble using relative paths as an option in a unix script which i'll call 'example.sh'.
contents of example.sh

Code: Select all

convert resize "$1" -resize 100x100 "$1"
When I execute

Code: Select all

sh example.sh "somedirectory/image.png"
it does not recognize the subdirectory (presumably because of the slash). I've tried a few different things, but it just doesn't seem to work when it's in a subdirectory. Does anyone know a way around this or to escape it properly? I'm using a linux distribution and a bash shell.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with unix subdirectory relative path as input fi

Post by fmw42 »

Are you sure that is the problem. What error messages do you get?

Try putting the full path to convert in your command and see if that works. Also try full paths to your script.

Relative paths should work. If not try full paths to your images. Be sure you have read write permissions.
rich2005
Posts: 32
Joined: 2012-04-09T11:07:36-07:00
Authentication code: 8675308

Re: Problem with unix subdirectory relative path as input fi

Post by rich2005 »

Maybe pass two variables to the script.

Code: Select all

#!/bin/bash

# cdpath=/.
cd $1
convert "$2" -resize 100x100 new_"$2"
mv new_$2 ../$2
cdpath will set a base for the relative path then
sh example.sh "somedirectory" "image.png" should work (just the names, no slashes)
edit: as you have guessed, that cdpath is not required.


renamed the output image because it will overwrite the existing.
move and rename the resized file up one level to the directory the script is in.

Question in the op what does the first resize do? Throws up an error here.

using ImageMagick 6.8.0-2 and PClinuxOS
Post Reply