How To: Using Cygwin and Bash Scripts (e.g., Fred's) with IM
How To: Using Cygwin and Bash Scripts (e.g., Fred's) with IM
I am not a programmer, nor am I versed in photo-editing, and am having trouble utilizing published scripts with IM. Given my predicament, I am not able to successfully follow the instructions given on Fred's webpage that directs one to utilize Cygwin in combination with IM when utilizing a Windows 7 based system. Is anyone aware of a documented process, tutorial, or video for Dummies that may help me utilize the "out-side IM" resource codes. For example, if I understood the process to use Fred's "downsize" script in a Window 7 environment, I do believe I could be successful with other scripts. Thanks in advance for anyone's help.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
Cygwin is required to run my scripts on Windows. I do not use Windows so cannot help much. But see http://www.imagemagick.org/Usage/windows/#cygwin. There are some Windows users who have been successful. Perhaps one of them could help.
If you get it installed and get errors from my script, let me know and I can probably figure out what the issue might be. One thing that always comes up is that the unix bc calculator is not installed with Cygwin by default. You have to check the custom install for it.
Some of the issues that Bonzo mentions below were resolve and had to do with line endings coming from textual output from IM commands.
If you get it installed and get errors from my script, let me know and I can probably figure out what the issue might be. One thing that always comes up is that the unix bc calculator is not installed with Cygwin by default. You have to check the custom install for it.
Some of the issues that Bonzo mentions below were resolve and had to do with line endings coming from textual output from IM commands.
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
From memory this has been discussed before and if you search the forum there will be a post about it and I believe the answer was even with Cygwin installed there were problems.
snibgo has some information on using Imagemagick on Windows; why not post an example of what you want to do and there may be another way to get what you want.
snibgo has some information on using Imagemagick on Windows; why not post an example of what you want to do and there may be another way to get what you want.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
A search of the forum for Cygwin returns these links that may be helpful:
viewtopic.php?f=1&t=25197&p=109195&hilit=Cygwin#p109195
viewtopic.php?f=26&t=23226&p=99258&hili ... red#p99258
viewtopic.php?f=26&t=23226&hilit=cygwin+fred&start=60
viewtopic.php?f=26&t=21271&p=86641&hili ... red#p86641
viewtopic.php?f=26&t=16538&hilit=cygwin+fred#p60556
viewtopic.php?f=26&t=16538&hilit=cygwin ... =30#p68944
viewtopic.php?f=1&t=25197&p=109195&hilit=Cygwin#p109195
viewtopic.php?f=26&t=23226&p=99258&hili ... red#p99258
viewtopic.php?f=26&t=23226&hilit=cygwin+fred&start=60
viewtopic.php?f=26&t=21271&p=86641&hili ... red#p86641
viewtopic.php?f=26&t=16538&hilit=cygwin+fred#p60556
viewtopic.php?f=26&t=16538&hilit=cygwin ... =30#p68944
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
If anyone can provide me direction/help, it would be greatly appreciated.
1) I have downloaded Cygwin with ALL add-ons including bc.
2) I have downloaded Fred's script "downsize", copied it to the bin folder of Cygwin, and renamed it as an exe file.
3) I have placed a jpg image on the c drive named Chart2.jpg
4) I've opened the command line window and changed my drive to the bin folder of Cygwin
5) At the command line, I input: downsize -s 200 -t 1 -c y C:Chart2.jpg test2.jpg
At this point the command line cursor moves to the next line and locks up.
All suggestions as to what I am not doing correctly to incorporate and run a script are appreciated.
1) I have downloaded Cygwin with ALL add-ons including bc.
2) I have downloaded Fred's script "downsize", copied it to the bin folder of Cygwin, and renamed it as an exe file.
3) I have placed a jpg image on the c drive named Chart2.jpg
4) I've opened the command line window and changed my drive to the bin folder of Cygwin
5) At the command line, I input: downsize -s 200 -t 1 -c y C:Chart2.jpg test2.jpg
At this point the command line cursor moves to the next line and locks up.
All suggestions as to what I am not doing correctly to incorporate and run a script are appreciated.
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
Correction to the 5) step in the previous note.
5) downsize -s 200 -t 1 -c y C/Chart2.jpg C/test2.jpg
5) downsize -s 200 -t 1 -c y C/Chart2.jpg C/test2.jpg
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
In addition to the 5 steps listed above, I also went into the Environment Variables' window of the computer's System Setting under Advanced Settings and appended ;C:\cygwin\bin to the Path name.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
When you say an exe file, do you mean downsize.exe or do you mean the permissions as executable. The former is not correct. The latter is correct.
I am not sure this is the correct way to specify full paths on Windows in Cygwin. Are your images located at the root of the C disk? That is usually not the normal way. Most people have their images in a subdirectory of C.
The best thing to do before trying one of my scripts, is to simply test if IM convert works.
Does that work. Or even simpler, does this work
If the latter works, try to cd to the the directory where your image is located and then
If that works, then try
If that does not work, then put the full path to where you have downsize located
Code: Select all
downsize -s 200 -t 1 -c y C/Chart2.jpg C/test2.jpg
The best thing to do before trying one of my scripts, is to simply test if IM convert works.
Code: Select all
convert C/Chart2.jpg C/test2.jpg
Code: Select all
convert logo: logo.jpg
Code: Select all
convert Chart2.jpg test2.jpg
Code: Select all
downsize -s 200 -t 1 -c y Chart2.jpg test2.jpg
Code: Select all
path2/downsize -s 200 -t 1 -c y Chart2.jpg test2.jpg
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
Not sure that is the correct syntax for the PATH in Cygwin, since it is unix and should be using / rather than \.jwtrexler wrote:In addition to the 5 steps listed above, I also went into the Environment Variables' window of the computer's System Setting under Advanced Settings and appended ;C:\cygwin\bin to the Path name.
But sorry, I have never really used Cygwin and cannot say. The only reference I have is http://www.imagemagick.org/Usage/windows/
Perhaps some user who has used Cygwin can comment more about syntax and file paths.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
Why did you rename it as an exe file? Perhaps this is correct, I don't know, but a .exe file is usually a binary file, containing binary instructions. If cygwin tries to load and run a script as if it was binary, that could cause problems.jwtrexler wrote:2) I have downloaded Fred's script "downsize", copied it to the bin folder of Cygwin, and renamed it as an exe file.
I suggest you create a much simpler script to start with, something like:
Code: Select all
#!/bin/bash
echo Hello world
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
Snibgo, I think we cross posted again. I said mostly the same thing in my earlier post. But I think he also needs help with Cygwin path syntax. Can you comment on his notes above about what path he is using for accessing his images and for modifying his PATH variable.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
Yes, our electrons whizzed past each other somewhere under the Atlantic Ocean, as they often do.
My current computer doesn't have cygwin, so I can't test. I think ...
... needs an extra slash before each C, thus:
Otherwise the script will look for a directory, within the current one, called "C".
Cygwin (I think) creates a root directory containing all the disk drives. A general root-around with the "ls" command should reveal the directory structure, eg:
EDIT: I should add that the command ...
... should successfully show the jpeg file, if it is in the root of the (Windows) C: drive.
My current computer doesn't have cygwin, so I can't test. I think ...
Code: Select all
downsize -s 200 -t 1 -c y C/Chart2.jpg C/test2.jp
Code: Select all
downsize -s 200 -t 1 -c y /C/Chart2.jpg /C/test2.jp
Cygwin (I think) creates a root directory containing all the disk drives. A general root-around with the "ls" command should reveal the directory structure, eg:
Code: Select all
ls .
ls ..
ls /
Code: Select all
ls /C/Chart2.jpg
snibgo's IM pages: im.snibgo.com
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
STATUS UPDATE: I have been successful with the first three suggestions by fmw42, however I did have to include colons after the C in the path names. I will know try to understand why the later two suggestions are not working. WRT to the question as to why I renamed the down loaded script, it was my understanding it needed to be placed in the bin file and have the extension to be .exe. IF that is not the case, then the lack of success I am experiencing with downsize may be attributed to this change. I will experiment some more and thanks for the help.
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
STATUS UPDATE (Supplement): The three I eluded to above that worked were those utilizing the Convert command, not the Downsize command.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM
Do not rename the file to .exe. You can leave it as downsize or downsize.sh. It is a text file not a binary file such as .exe as snibgo explained earlier. But you must set permissions to make it executable. See the Pointers on my web site for the other things to edit or do with the file, including make the tmp directory /tmp rather than ./.
Pointers for use:
Be sure you have installed the unix calculator, bc. It is an option that you may have to select when installing unix.
Download the script
Change the name to add or remove the .sh as desired when running
Set the script to executable (chmod u+x)
Find the full path to where IM (convert) resides by typing in a shell terminal window: type -a convert
If type -a convert returns more than one path, type in a shell terminal window: path2/convert -version, where path2 is each of the paths found. Decide which version of IM you want to use.
Modify your PATH environment variable so that it includes the full path to where IM (convert) resides (often /usr/bin or /usr/local/bin). This can be done by editing your .profile file.
Alternately, edit the script somewhere between the comments and the first use of any IM command, such as just below the defaults section to add the following two lines:
imdir="path2" #(such as imdir="/usr/local/bin" or imdir="/usr/bin")
PATH="${imdir}:${PATH}"
Open a shell terminal window
bash /fullpathto/scriptname(.sh) arguments /fullpathto/inputimage /fullpathto/outputimage
To avoid the bash and just use scriptname(.sh) ... set your PATH to contain the location of the script
Optionally edit the script to change the default directory (found after the defaults section) from dir="." to dir="/tmp"
If you have trouble with filenames with spaces in them, then you will need to edit the script in several places until I have time to review and fix all my scripts. Find where infile and outfile (maskfile or any others) are defined at the end of the argument trapping section. Make sure to enclose in double quotes any declarations of those files that include $1, $2, etc, such as infile="$1", etc. Find any occurrences of $infile or $outfile and enclose them in double quotes as "$infile", etc.
These are general unix instructions. Modify the paths as appropriate for Cygwin on Windows.
Pointers for use:
Be sure you have installed the unix calculator, bc. It is an option that you may have to select when installing unix.
Download the script
Change the name to add or remove the .sh as desired when running
Set the script to executable (chmod u+x)
Find the full path to where IM (convert) resides by typing in a shell terminal window: type -a convert
If type -a convert returns more than one path, type in a shell terminal window: path2/convert -version, where path2 is each of the paths found. Decide which version of IM you want to use.
Modify your PATH environment variable so that it includes the full path to where IM (convert) resides (often /usr/bin or /usr/local/bin). This can be done by editing your .profile file.
Alternately, edit the script somewhere between the comments and the first use of any IM command, such as just below the defaults section to add the following two lines:
imdir="path2" #(such as imdir="/usr/local/bin" or imdir="/usr/bin")
PATH="${imdir}:${PATH}"
Open a shell terminal window
bash /fullpathto/scriptname(.sh) arguments /fullpathto/inputimage /fullpathto/outputimage
To avoid the bash and just use scriptname(.sh) ... set your PATH to contain the location of the script
Optionally edit the script to change the default directory (found after the defaults section) from dir="." to dir="/tmp"
If you have trouble with filenames with spaces in them, then you will need to edit the script in several places until I have time to review and fix all my scripts. Find where infile and outfile (maskfile or any others) are defined at the end of the argument trapping section. Make sure to enclose in double quotes any declarations of those files that include $1, $2, etc, such as infile="$1", etc. Find any occurrences of $infile or $outfile and enclose them in double quotes as "$infile", etc.
These are general unix instructions. Modify the paths as appropriate for Cygwin on Windows.