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.
Related
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?
I'm trying to create a notification from a downloaded image:
I tried:
wget -q https://i.ytimg.com/vi/zqKrpw36xnU/maxresdefault.jpg -O/tmp/thumbnail.jpg
notify-send something -i /tmp/thumbnail.jpg
and
wget -q https://i.ytimg.com/vi/zqKrpw36xnU/maxresdefault.jpg -O/tmp/thumbnail.jpg
convert -density 384 -scale 256 /tmp/thumbnail.jpg /tmp/thumbnail.ico
notify-send something -i /tmp/thumbnail.ico
But they both show random previously downloaded image, despite been replaced...
Am I doing something wrong? Is there a better tool than notify-send?
I'm in ubuntu 20.04 with notify-send 0.7.9.
Requirement is to convert PDF to PCL with a macro embedded (currently testing this on Windows, however I will need to use this runtime in the application and print it from UNIX). The macro will be used later in another document to embed this cropped image and printed on one single page. I will be using PCL escape codes to call the MacroNumber and then the image will be printed. (You can consider this as a logo image.)
I am able to convert the PDF with whitespace to just the PDF without any whitespace by using CropBox.
"c:\progra~1\gs\gs9.15\bin\gswin64.exe" -o _sourcePDFcropped.pdf \
-sDEVICE=pdfwrite -c "[/CropBox [1 140 320 650] /PAGES pdfmark" \
-f _sourcePDF.pdf
However, when I convert this _sourcePDFcropped.pdf to PCL, this still adding whitespace.
"c:\progra~1\gs\gs9.15\bin\gswin64c.exe" -dBATCH -dNOPAUSE \
-sDEVICE=pxlcolor -g100x200 -sOutputFile=_sourceFedGroundCroppedTest.pcl \
-f _sourceFedGroundCropped.pdf
I tried using MKPCL and it does the job. Because it doesn't have much support, I am trying to use Ghostscript.
MKPCL.EXE -c4 -t -m 100 -p Image.jpg Image.MAC
I also tried ImageMagick which internally uses Ghostscript. So I am guessing, if I use the right switches in GS, I should be able to achieve my goal.
Input PDF File: Click Here
P.S: I have seen other PDF to PCL queries on Stackoverflow, others are more of straight forward PDF to PCL. Mine is to crop the PDF and output should be PCL.
Question continued: Link
I processed the sample input PDF with the following command line, using a self-compiled Ghostscript v9.16 (unreleased, from current GhostPDL GIT sources):
gs -o - \
-sDEVICE=pdfwrite \
-c "[/CropBox [1 140 320 650] /PAGES pdfmark" \
-f source.pdf \
\
| gs -o tst.pcl \
-sDEVICE=pxlcolor \
-dUseCropBox \
-f -
(As you may well have noticed, I'm connecting 2 different Ghostscript commands through a pipe in order to save writing a temporary PDF file to disk.)
If you want to do the same on Windows, the command line in a cmd.exe/DOS box would be:
gswin64c.exe -o - ^
-sDEVICE=pdfwrite ^
-c "[/CropBox [1 140 320 650] /PAGES pdfmark" ^
-f source.pdf ^
^
| gswin64c.exe -o tst.pcl ^
-sDEVICE=pxlcolor ^
-dUseCropBox ^
-f -
Then I opened it with the self-compiled PCL viewer (also from GhostPDL sources), pcl6:
pcl6 tst.pcl
This is a screenshot showing the pcl6 window:
As KenS also pointed out: it is important to use -dUseCropBox when processing the cropped PDF intermediate data!
Adding a CropBox doesn't really do much, it leaves the PDF exactly the same, but adds a CropBox entry for the page. GS will usually use the MediaBox, not the CropBox, so adding a CropBox to a PDF has no effect.
You could try adding -dUseCropBox. If the white space you think is being added is in fact present in the original PDF, but masked by the CropBox, then using -dUseCropBox will have GS use the CropBox when rendering the PDF.
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
I split PDF into pages with help of usable command line:
for G in $(seq 1 $(pdfinfo 47.pdf | sed -n 's/Pages:[^0-9]*\([0-9]*\).*/\1/p')) ; do
gs \
-dSAFER \
-sDEVICE=pdfwrite \
-dBATCH \
-dNOPAUSE \
-dFirstPage=$G \
-dLastPage=$G \
-o $G.pdf \
47.pdf ;
done
But some pages appears without text (Graphics are still present)
So, I have tried to extract embedded font from PDF:
gs -q -dNODISPLAY extractFonts.ps -c "(47.pdf) extractFonts quit"
These fonts I have installed in system Fonts folder.
After that, I have repeat splitting and no changes were happened.
How-to be sure that pages will be extracting correctly, I have no idea now.
Ghostscript and pdfwrite are not actually intended for the purpose of splitting PDF files up, there are other tools which will probably work better, why not try pdftk ?
If you really want to use Ghostscript then I would advise you to get hold of the latest bleeding-edge code from the Git repository, in that code the pdfwrite device will accept an output file name containing a '%d' and will write one file per page.
Beyond that, it seems most likely to me that you are simply experiencing a bug, rather than 'losing the font', if the font was missing the text would still be ther but in a differnt font. Which version of GS are you using ?