How To: Using Cygwin and Bash Scripts (e.g., Fred's) with IM

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
jwtrexler
Posts: 31
Joined: 2014-07-03T22:03:37-07:00
Authentication code: 6789

How To: Using Cygwin and Bash Scripts (e.g., Fred's) with IM

Post by jwtrexler »

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.
User avatar
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

Post by fmw42 »

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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM

Post by Bonzo »

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.
jwtrexler
Posts: 31
Joined: 2014-07-03T22:03:37-07:00
Authentication code: 6789

Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM

Post by jwtrexler »

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.
jwtrexler
Posts: 31
Joined: 2014-07-03T22:03:37-07:00
Authentication code: 6789

Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM

Post by jwtrexler »

Correction to the 5) step in the previous note.

5) downsize -s 200 -t 1 -c y C/Chart2.jpg C/test2.jpg
jwtrexler
Posts: 31
Joined: 2014-07-03T22:03:37-07:00
Authentication code: 6789

Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM

Post by jwtrexler »

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.
User avatar
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

Post by fmw42 »

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.

Code: Select all

downsize -s 200 -t 1 -c y C/Chart2.jpg C/test2.jpg
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.

Code: Select all

convert C/Chart2.jpg C/test2.jpg
Does that work. Or even simpler, does this work

Code: Select all

convert logo: logo.jpg
If the latter works, try to cd to the the directory where your image is located and then

Code: Select all

convert Chart2.jpg test2.jpg
If that works, then try

Code: Select all

downsize -s 200 -t 1 -c y Chart2.jpg test2.jpg
If that does not work, then put the full path to where you have downsize located

Code: Select all

path2/downsize -s 200 -t 1 -c y Chart2.jpg  test2.jpg
User avatar
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

Post by fmw42 »

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.
Not sure that is the correct syntax for the PATH in Cygwin, since it is unix and should be using / rather than \.

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.
snibgo
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

Post by snibgo »

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.
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.

I suggest you create a much simpler script to start with, something like:

Code: Select all

#!/bin/bash
echo Hello world
Get this to run successfully before moving on to a complex IM script.
snibgo's IM pages: im.snibgo.com
User avatar
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

Post by fmw42 »

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.
snibgo
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

Post by snibgo »

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 ...

Code: Select all

downsize -s 200 -t 1 -c y C/Chart2.jpg C/test2.jp
... needs an extra slash before each C, thus:

Code: Select all

downsize -s 200 -t 1 -c y /C/Chart2.jpg /C/test2.jp
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:

Code: Select all

ls .
ls ..
ls /
EDIT: I should add that the command ...

Code: Select all

ls /C/Chart2.jpg
... should successfully show the jpeg file, if it is in the root of the (Windows) C: drive.
snibgo's IM pages: im.snibgo.com
jwtrexler
Posts: 31
Joined: 2014-07-03T22:03:37-07:00
Authentication code: 6789

Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM

Post by jwtrexler »

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.
jwtrexler
Posts: 31
Joined: 2014-07-03T22:03:37-07:00
Authentication code: 6789

Re: How To: Using Cygwin and Scripts (e.g., Fred's) with IM

Post by jwtrexler »

STATUS UPDATE (Supplement): The three I eluded to above that worked were those utilizing the Convert command, not the Downsize command.
User avatar
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

Post by fmw42 »

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.
Post Reply