I am using Imageimagick to crop arieal images in equal sizes.
Searching Google imagemagick tutorials led me to Fred Weinhaus scripts tutorial which I followed. When I am passing the command on bash or cmd based on syntax given in this website (bash /fullpathto/scriptname.sh with arguments /fullpathto/inputimage /fullpathto/outputimage)
I am getting error
$ overlapcrop -s 128 -o 50% -m matrix -M -L \
-R 'F:\bash\top_potsdam_2_10_RGB' 'F:\bash\o.jpg'
error Invalid Parameter - F:\bash\top_potsdam_2_10_RGB
FILE F:\bash\top_potsdam_2_10_RGB DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE
Even if we set the directory in the path, we get the same error:
$ overlapcrop -s 128 -o 50% -m matrix -M -L -R top_potsdam_2_10_RGB.png o.png
--Screenshots of imagemagick --help and convert --help
error I am getting
Windows is useless when it comes to quoting, so maybe try escaping the % sign by adding a second one or a caret (^) in front of it.
Also, try removing the F: from the paths and try putting the files in the current directory in case the slashes are causing errors.
Finally, you may have your PATH set incorrectly so that when the script executes the convert command it finds the Windows utility that converts filesystems to NTFS rather than the ImageMagick utility that converts images.
Try running:
convert /?
and seeing if you get an error/help message from Windows CONVERT.EXE or something from ImageMagick. If you get the Windows one, your PATH is incorrect and you need to put the directory where you installed ImageMagick ahead (in front of) C:\WINDOWS\System32 or wherever Windows CONVERT.EXE lives and restart your Command Prompt window.
Related
I am trying to move all text files with a specific name in them from one directory to another using bash on a windows machine in cygwin. The code is below and but I am not sure how to reference a windows path in bash. Thank you :).
for i in "C:\Users\cmccabe\Desktop\annovar"; do
mv $i"\"*multianno.txt "C:\Users\cmccabe\Desktop\all""\"basename $i`multianno.txt
done
mv: cannot stat ‘C:\\Users\\cmccabe\\Desktop\\annovar\\*multianno.txt’: No such file or directory
You should use cygpath, which is a cygwin utility for converting windows to/from cygwin paths.
Without additional arguments it will transform a given windows path to its cygwin equivalent, which is what you want :
mv $(cygpath "windows_src") $(cygpath "windows_dst")
I wasn't sure it would work with paths containing jokers, but it looks like it does :
$ cygpath "C:\path\*a*"
/cygdrive/c/path/*a*
I am trying to navigate to this below path in cygwin,
C/Program Files (x86)/temp/lfc/utilities
but unfortunately, it shows the below error
$ cd C/Program Files (x86)/temp/lfc/utilities
bash: syntax error near unexpected token `('
Could you please let me know, what is wrong here..
The command:
cd C/Program Files (x86)/temp/lfc/utilities
is trying to call cd with three arguments rather than the correct one:
C/Program
Files
(x86)/temp/lfc/utilities
and the third of those arguments contains characters that cause bash some grief - they're actually defined as metacharacters and, as per the bash doco:
Each of the metacharacters listed above under DEFINITIONS has special meaning to the shell and must be quoted if it is to represent itself.
Just surround the whole lot in quotes, like:
cd '/cygdrive/C/Program Files (x86)/temp/lfc/utilities'
You'll notice I've also prefixed it with the CygWin cygdrive mount point. I'm fairly certain that's still needed, at least from the version I installed a couple of months back.
Cygwin uses POSIX path nomenclature. To easily convert a Windows path into a Cygwin path you can use the cygpath tool:
$ cygpath 'C:\Program Files\foo'
/cygdrive/c/Program Files/foo
Also this tool can convert POSIX path to Windows:
$ cygpath -w '/cygdrive/c/Program Files/foo'
C:\Program Files\foo
A third solution is to drag and drop a file or folder from the Windows explorer directly into your mintty terminal. You will get you Windows path directly converted into the Cygwin's format.
You could also use PROGRA~1, PROGRA~2 and PROGRA~3 like this :
cd /cygdrive/c/PROGRA~1 is equivalent to cd
/cygdrive/c/Programmes
cd /cygdrive/c/PROGRA~2 is equivalent to cd
/cygdrive/c/Program\ Files\ \(x86\)
cd /cygdrive/c/PROGRA~3 is equivalent to cd
/cygdrive/c/ProgramData
You can directly use windows paths with:
cd $(cygpath -u "C:\Program Files (x86)\temp\lfc\utilities")
This is useful for environment variables like:
cd $(cygpath -u "$USERPROFILE")/Downloads
cd "$(cygpath -u "$PROGRAMFILES")/Program Name"
You can know more about cygpath on https://cygwin.com/cygwin-ug-net/cygpath.html
I get an error when using a symbolic link in gnuplot:
on l: drive
plot "/j/projMainpips/Aggregate/dailyStats.txt" u 1:4 w l lw 1
warning: Skipping unreadable file "/j/projMainpips/Aggregate/dailyStats.txt"
No data in plot
The link was created as:
ln -s //xxx.yy.xx.y/Users/spence/JobsStuff/ /j
If I don't use the link, it works fine:
on h: in folder /j
plot "projMainpips/Aggregate/dailyStats.txt" u 1:4 w l lw 1
How can I enable use of symlinks in gnuplot?
I've tested symlinks to UNC paths under Cygwin 32, and it works here.
Are you using the Cygwin version of gnuplot? You will get such errors if you try to use the native Win32 port of gnuplot instead.
If you can open the file in a Cygwin text editor, that shows that the symlink works:
vi /j/projMainpips/Aggregate/dailyStats.txt
Another way to run into trouble here is to edit /etc/fstab to drop the cygdrive prefix. If you do that, your syntax is going to try looking for a J: system drive. You'd need to use more than a single letter to avoid this problem or revert fstab to its original form.
When you are executing a native Windows application from Cygwin, you should use cygpath to translate paths from Unix to Windows format. You can try it with symlink too, maybe it'll work and translate the target path of the symlink to the Windows version path. I didn't try that, so I'm not sure if it works, but it's worth trying.
Example use:
# convert specified Cygwin path to the Windows path
cygpath -w ~
notepad `cygpath -w ~/test.txt`
I installed Strawberry Perl to run the rouge program in Windows. But when I want to run my program, I receive an error message that you can see on the image:
The system can't find the path specified.
My code is attempting to run "ROUGE-1.5.5.pl" but i think the system can't find this file. So I think maybe I don't initialize the path correctly?
I change my code to :
#!/usr/bin/perl
use Cwd;
$curdir=getcwd;
$ROUGE="..\ROUGE-1.5.5.pl";
chdir("sample-test");
$cmd="$ROUGE -e ..\data -c 95 -2 -1 -U -r 1000 -n 4 -w 1.2 -a DUC2002-ROUGE.in.26.spl.xml > ..\sample-output\output.out";
print $cmd,"\n";
system($cmd);
chdir($curdir);
and i receive this error:
Missing braces on \o{} at C:\runROUGE-test.pl line 7, near "$ROUGE" Execution of C:\runROUGE-test.pl aborted due to compilation errors.
As per the screen shot, you are attempting to run \ROUGE-1.5.5.pl where you probably want it without the spurious backslash (or with ..\ROUGE-1.5.5.pl if the parent directory is not on your PATH).
Similarly, you probably want the output in sample-output\output.out, or even just output.out, not \sample-output\output.out unless you specifically have a folder C:\sample-output for this purpose.
The backslash is significant; it is the absolute path to the root (of the current drive, on Windows). ..\ is the relative path to the parent folder.
Why are you writing a Perl script to run a Perl script, though? Either a simple batch file, or copy/pasting the command directly at the DOS prompt would seem like a less roundabout solution.
The problem is that when you are outputting the contents of the program to the file output.out in folder sample-output, the sample-output folder does not exist.
Command Prompt will not create the folders for you, only the files. Try creating a directory first called "sample-output" (In your drive root) such that the path resolves to something like C:\sample-output and run it again.
If the same problem results, try using an absolute path such as C:\sample-output\output.out instead.
Background
OpenOffice Writer lacks the ability to link to an ASCII text source file, apply syntax highlighting, wrap it in a frame, and update the frame contents whenever the source file changes. However, OpenOffice Writer can link to images, and will update the images automatically when they change.
Problem
The images need to be high-resolution (300 dpi or greater) with syntax colouring appropriate for a white background (i.e., a printed page).
Question
How can high-quality images be created automatically from source code files, such as:
SQL;
PostgreSQL functions;
Java;
bash scripts; and
R and PL/R?
Attempts
Most attempts have been a variation on the following theme:
$ enscript --color -f Courier12 -B -1 --highlight=sql -h -o - source.sql |\
convert - -trim -border 10 source.png
There are a few problems with this approach:
The resolution is lacking (using -resample and -density offer no improvement).
The syntax highlighting is unsuitable for a white page (can probably change enscript's colour theme).
Using Courier100 produces several .png files, which would need to be stitched together.
The -border 10 unexpectedly changes the background colour from white to lightgray.
Manual Solution
Converting the source files to PostScript -- avoiding ImageMagick altogether -- and then importing them into The GIMP will produce the desired results. Unfortunately, that solution involves a bit of manual work, and my GIMP batch programming experience is next to nil.
Software Requirements
The following software packages are available for both Windows and Linux systems, and are required for a complete, working solution:
gvim - Used to export syntax highlighted source code to HTML.
moria - Colour scheme for syntax highlighting.
wkhtmltopdf - Converts HTML documents to PDF or PostScript (PS) documents.
Ghostscript - Used to convert PS to PNG.
ImageMagick - Used to trim the PNG and add a border.
General Steps
Here is how the solution works:
Load the source code into an editor that can add splashes of colour.
Export the source code as an HTML document (with embedded FONT tags).
Convert the HTML document to a PS file.
Convert the PS file to a PNG file.
Trim the white border of the PNG and the overzealous source code border.
Add a border around the image, using the same background colour as the HTML document.
Delete temporary files.
Installation
Install the components into the following locations:
gvim - C:\Program Files\Vim
moria - C:\Program Files\Vim\vim73\colors
wkhtmltopdf - C:\Program Files\wkhtml
Ghostscript - C:\Program Files\gs
ImageMagick - C:\Program Files\ImageMagick
Note: ImageMagick has a program called convert.exe, which cannot supersede the Windows convert command. Because of this, the full path to convert.exe must be hard-coded in the batch file (as opposed to adding ImageMagick to the PATH).
Environment Variables
Add or update the following environment variables:
GS_LIB = C:\Program Files\gs\gs9.00\lib
GS_PROG = C:\Program Files\gs\gs9.00\bin\gswin32.exe
PATH = "C:\Program Files\Vim\vim73";"C:\Program Files\wkhtml";"C:\Program Files\gs\gs9.00\bin"
Batch File
Here is the batch source text:
#ECHO OFF
ECHO Converting %1 to %1.html ...
gvim -e %1 -c "set nobackup" -c ":colorscheme moria" -c :TOhtml -c wq -c :q
ECHO Converting %1.html to %1.ps ...
wkhtmltopdf --quiet --dpi 1200 %1.html %1.ps
ECHO Converting %1.pdf to %1.png ...
IF EXIST %1.png DEL /q %1.png
gswin32 -q -dBATCH -dNOPAUSE -dSAFER -dNOPROMPT ^
-sDEVICE=png16m -dDEVICEXRESOLUTION=600 -dDEVICEYRESOLUTION=600 ^
-dDEVICEWIDTH=4958 -dDEVICEHEIGHT=7017 -dNOPLATFONTS ^
-dTextAlphaBits=4 -sOutputFile=%1.png %1.ps
ECHO Trimming %1.png ...
move %1.png %1.orig.png
"C:\Program Files\ImageMagick\convert.exe" -trim +repage -trim +repage ^
-bordercolor "#f0f0f0" -border 25x25 %1.orig.png %1.png
ECHO Removing old files ...
IF EXIST %1.orig.png DEL /q %1.orig.png
IF EXIST %1.html DEL /q %1.html
IF EXIST %1.ps DEL /q %1.ps
Another option is to make use of catage, CodeSnap, PolaCode or carbon-now-cli.
CodeSnap and PolaCode are Visual Studio Code extensions, and it may be difficult to use them from the command line, but they are simple to use. Follow the instructions when installing them into your editor. This solution works for all operating systems supported by Visual Studio Code.
If you are using a Debian-based Linux distribution, and you have Docker installed, then you can create a catage Docker image using the following shell script:
#!/bin/bash
sudo docker build -t catage:local - <<EOF
FROM buildkite/puppeteer
USER node
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
RUN mkdir /home/node/.npm-global
WORKDIR /home/node/app
RUN npm install -g catage
EOF
Similarly, a carbon-now-cli Docker image can be created with the following script:
#!/bin/bash
sudo docker build -t carbon-now:local - <<EOF
FROM alekzonder/puppeteer
USER root
RUN apt-get update
RUN apt-get install git -yq
RUN yarn global add carbon-now-cli
USER pptruser
EOF
Use these Docker images in a shell script as follows, to generate PNG images from your code snippets:
#!/bin/bash
alias catage="sudo -E docker run --rm -it -v $PWD:/home/node/app catage:local catage"
alias carbon-now="sudo -E docker run --rm -it --init --cap-add=SYS_ADMIN --shm-size=1gb --user pptruser -v $PWD:/home/pptruser/app --workdir /home/pptruser/app carbon-now:local carbon-now"
catage --language java --no-line-numbers --theme Material --frame-title "My Code Snippet" --format png "my_code_snippet.java" "my_code_snippet.png"
carbon-now "my_code_snippet.java" --target "my_code_snippet" --headless
The Docker approach works for all operating systems supported by Docker. You may have to modify the above shell script examples according to the capabilities of your operating system, but the basic commands remain the same.