Problem running bash-script in wsl with convert function (ImageMagik) - WSL - windows-subsystem-for-linux

A Windows user here, with little, almost zero experience with Linux.
While procrastinating as I wrote my thesis, I encountered a script to convert the pdf to a gif using the command convert from ImageMagik. Here is the result of the gif:
https://raw.githubusercontent.com/npcardoso/PhDThesis/master/thesis.gif
Since I use Windows, I activated WSL and installed Ubuntu.
This is the script I am using:
#!/bin/bash
tmp_dir=$(mktemp -d -t cho-XXXXXXXXXX)
echo $tmp_dir
cd $(dirname $0)
function remove_alpha() {
convert -monitor -alpha remove -background white -antialias $*
}
function to_gif() {
convert -monitor -loop 0 -strip -layers OptimizePlus -delay 50 -antialias $*
}
remove_alpha -density 50 thesis/main.pdf $tmp_dir/thesis_raster.pdf
pdfnup $tmp_dir/thesis_raster.pdf {},1- -o $tmp_dir/thesis_nup.pdf
to_gif $tmp_dir/thesis_nup.pdf thesis.gif
rm -rfv $tmp_dir
However, I am not able to run the script successfully. I get the following errors:
these errors
I do not know how to get rid of these errors. I even tried removing the functions, but I still get the error about the $'.\r': No such file or directory.
errors without the functions
Any guidance?

Related

Google Colab Blender render Error: cannot read file

Trying to render a single frame
following this script "Blender_script_for_Google_Colab_using_the_GPU.ipynb"
by- https://github.com/donmahallem
Successfully mounted GDrive and installed Blender.
Executed all the cells from top to bottom, one by one.
This is the OUTPUT of final Cell
found bundled python: /content/blender2.83.12/2.83/python
Error: Cannot read file '/content/{/content/drive/MyDrive/Blender/donut.blend}': No such file or directory
<bpy_struct, CyclesPreferences at 0x7f6366c38ba8>
Device found CUDA
Activating <bpy_struct, CyclesDeviceSettings("Tesla T4")>
Activating <bpy_struct, CyclesDeviceSettings("Tesla T4")>
Blender quit```
ANSWER
It should be like this
!/content/blender2.83.12/blender -P './setgpu.py' -b -noaudio '/content/drive/MyDrive/Blender/donut.blend' -E CYCLES -o '/content/drive/MyDrive/Blender/test_mixed_####.png' -f 1 |& tee '/content/drive/MyDrive/Blender/log.txt'
NOT like this
!/content/blender2.83.12/blender -P './setgpu.py' -b -noaudio '{/content/drive/MyDrive/Blender/donut.blend}' -E CYCLES -o '{/content/drive/MyDrive/Blender/test_mixed_####.png}' -f 1 |& tee '/content/drive/MyDrive/Blender/log.txt'
In short I forgot to remove the curly brackets {} from "Blend_file_path" and "Output_path"
I believe you should use 'My Drive' rather than 'MyDrive' in your directory path.

ImageMagick Invalid Image Index

A week ago I followed this tutorial, and it successfully worked (even with some changes I did), but today it just won't work.
The edited code is this:
SCREENSHOTFOLDER="/home/pk/screenshots"
FILE="${1}"
FILENAME="${FILE##*/}"
FILEBASE="${FILENAME%.*}"
# drop shadow: 60% opacity, 10 sigma, +0x +10y
convert "${FILE}" \( +clone -background black -shadow 70x15+5+10 \) +swap -background white -layers merge +repage "$SCREENSHOTFOLDER/${FILEBASE}.png"
notify-send -u critical -t 1 "${FILEBASE}.png saved."
xclip -selection clipboard -t image/png -i "$SCREENSHOTFOLDER/${FILEBASE}.png"
that code is run by this script:
escrotum -s -e '/home/pk/ss/dropshadow-c.sh $f'
then, I tried to debug it but when I run escrotum -s -e '/home/pk/ss/dropshadow-c.sh $f' I get this:
convert: invalid image index `2021-04-18-201820_839x396_escrotum.png' # error/list.c/CloneImages/282.
convert: no such image `+clone' # error/convert.c/ConvertImageCommand/1027.
xclip: /home/pk/screenshots/2021-04-18-201820_839x396_escrotum.png: No such file or directory
The problem was that ImageMagick has a bug in the version I used, I downgrade it and it works.

Run RapSearch-Program with Torque PBS and qsub

My problem is that I have a cluster-server with Torque PBS and want to use it to run a sequence-comparison with the program rapsearch.
The normal RapSearch command is:
./rapsearch -q protein.fasta -d database -o output -e 0.001 -v 10 -x t -z 32
Now I want to run it with 2 nodes on the cluster-server.
I've tried with: echo "./rapsearch -q protein.fasta -d database -o output -e 0.001 -v 10 -x t -z 32" | qsub -l nodes=2 but nothing happened.
Do you have any suggestions? Where I'm wrong? Help please.
Standard output (and error output) files are placed in your home directory by default; take a look. You are looking for a file named STDIN.e[numbers], it will contain the error message.
However, I see that you're using ./rapsearch but are not really being explicit about what directory you're in. Your problem is therefore probably a matter of changing directory into the directory that you submitted from. When your terminal is in the directory of the rapsearch executable, try echo "cd \$PBS_O_WORKDIR && ./rapsearch [arguments]" | qsub [arguments] to submit your job to the cluster.
Other tips:
You could add rapsearch to your path if you use it often. Then you can use it like a regular command anywhere. It's a matter of adding the line export PATH=/full/path/to/rapsearch/bin:$PATH to your .bashrc file.
Create a submission script for use with qsub. Here is a good example.

Adobe Bridge/Photoshop - Resize Longest Side and Save For Web, Overwriting Original

Here goes!
I have a folder with dozens of sub folders which contain sub folders
I would like to resize all images which have any length greater than 800px so the new length becomes 800px
but the image maintains the same ratio. For example if an image was
1200x600px it would resize it to 800x400px
I would then like it to be
"Saved For Web" or optimised at the very least It would then have to
overwrite the original since I am using GIFs, JPEGs, JPGs and PNGs
Can this be done all together, can any part be easily done?
I'm on a Mac
Thanks in advance
I would do it with ImageMagick. The command is like this, but I would create a backup first:
#!/bin/bash
find . -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.gif" -o -iname "*.png" | \
while read i; do
echo convert "$i" -resize 800x800 -quality 85% "$i"
done
That says... starting at dot (the current directory, you can put a different starting directory here if you like), find all files called ".JPG" or ".JPEG" or ".GIF" or ".PNG", regardless of upper or lower case, in this directory and all directories below, and pass their names into the while loop. The convert command says to resize the image so neither side is over 800px and the aspect ratio is retained, then optimise for Web and overwrite original file.
At the moment, it does nothing, it just shows you the command it would run, so you would need to remove the word echo and run it again if you like it. Run some tests on a single image or two first.
You could add -strip between -resize and -quality to remove EXIF data (date/time photo was taken, camera make and lens etc) to make the files smaller too. You can also insert a Copyright string and an IPTC profile to give Copyright, Contact, Source, Object and Credits information - just ask me.
To run the script above, save it in a file called resizer, then go into Terminal and do this:
chmod +x resizer # Just do this one time to make the script executable
./resizer # Run the script
To install ImageMagick on a Mac, use homebrew. Go to here and install it with the line of code there. Then do:
brew install imagemagick
If you don't like ImageMagick, you could maybe use sips which is built into OSX but it is nowhere near as flexible. If you wanted to try that, the basic command would be:
sips -Z 800 somefile.jpg
and it will then resize the image to max 800px on either side. Not sure how to optimise or strip EXIF in sips, nor if it works for PNG and GIF files... Your command would then become:
#!/bin/bash
find . -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.gif" -o -iname "*.png" | \
while read i; do
echo sips -Z 800 "$i"
done

no output file generated when using Ghostscript to convert PDF to TIFF

Here is the command I use:
gs -r300 -q -dNOPAUSE -sDevice=tiffgray -sOutputFile=sample1.tiff sample1.pdf -c quit
I don't see sample1.tiff in my current working directory. I'm running OS Mavericks.
Try running without -q so that the messages aren't suppressed, Ghostscript is probably trying to tell you what's wrong.