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

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

Related

Problem running bash-script in wsl with convert function (ImageMagik) - WSL

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?

Move file, change permissions and rename it keeping the same extesion

Using zsh 5.2 on Fedora 24 workstation.
I want to be programatically able to:
move an image file (can have jpg/ jpeg/ png/ JPG/ PNG extensions)
from /tmp/folder1 to ~/Pictures
This file will have the same few initial characters --- prefix111.jpg OR prefix222.png, etc.
rename the file such that samefilename.JPG becomes 20161013.jpg
20161013 is today's date in yyyymmdd format
Note that the extension becomes small letters
And JPEG or jpeg becomes jpg
change the permissions of the moved file to 644
All at one go.
If there are multiple prefix* files, the command should just fail silently.
I will initially like to do it at the command prompt with an option to add a cron job later. I mean, will the same zsh command/ script work in cron?
I am sure, this is doable. However, with my limited shell knowledge, could only achieve:
mv /tmp/folder1/prefix-*.JPG ~/Pictures/$(date +'%Y%m%d').jpg
Problems with my approach are many. It does not handle capitalization, does not take care of different extensions and does not address the permission issue.
How about this:
#!/bin/sh
FILES="/tmp/folder1/prefix*.jpg /tmp/folder1/prefix*.jpeg /tmp/folder1/prefix*.png h/tmp/folder1/prefix*.JPG /tmp/folder1/prefix*.PNG"
if [ $(ls $FILES | wc -l ) -gt 1 ]; then
exit 1
fi
if [ $(ls $FILES | grep -i '\.png$') ]; then
SUFF=png
else
SUFF=jpg
fi
DEST=$HOME/Pictures/$(date +'%Y%m%d').$SUFF
mv $FILES $DEST
chmod 644 $DEST

How to remove right and left margins from a PDF file using Ghostscript or any other command line tool?

I've been trying several GS commands to remove the margins from right and left side of a PDF file such as:
gs \
-q -dNOPAUSE -dBATCH \
-sDEVICE=pdfwrite \
-dSAFER \
-dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/printer \
-dSubsetFonts=true \
-dEmbedAllFonts=true \
-sPAPERSIZE=a4 \
-sOutputFile=d:\\ghost\\gs\\bin\\shiftedgulf.pdf \
-c <</BeginPage{0.9 0.9 scale 29.75 42.1 translate}>> setpagedevice \
-f d:\\ghost\\gs\\bin\\gulf.pdf"
but its like nothing is happening, my question is there any effective, direct and clear way to achieve this ?
Maybe this questions is duplicated but I tried most of the scripts and none of them is giving me any result, any other command line tool might be suggested is fine as well.
PDF files don't have 'margins'. The content is placed on the page, which may leave white space at the edges of the media, but its not a margin as such.
I'd need to see the PDF file to have any chance of figuring out what you're trying to achieve, and why what you are doing doesn't work. Setting the PAPERSIZE to A4 seems like a bad start though. You probably want to set a specific medi asize and set -dFIXEDMEDIA so that the PDF interpreter doesn't overrride it.
You may want to study this other Stackoverflow answer to a similar question
PDF - Remove White Margins
and you'll probably be able to achieve what you want....
Thank you all for the answers i found very easy and direct to the point tool, it called briss all you need is downloading the JAR briss-0.0.14 and run the command :
java -jar briss-0.0.14.jar -s original.pdf -d cropped.pdf -c 0.11/0.08/0.11/0.08:0.11/0.08/0.11/0.08
and thats all :)

Merged PDFs Blank

Trying to merge all pdfs in a directory using GhostScript 9.06 64bit in a .bat file
The following, makes merged.pdf, but it is 1 page and blank
call gswin64c -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf *.pdf
If I actually specify which PDFs to merge it works fine. What gives?
call gswin64c -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf 1.pdf 2.pdf 3.pdf
You can't specify wildcards on the Ghostscript command line, simple as that.
Since GS didn't find a file called '*.pdf' it didn't execute any marking operations, in this case you get a blank file.
Ghostscript cannot do wildcard expansions by itself.
If you call gs ... *.pdf from inside a shell which can do wildcard expansion, it will work nevertheless.
There is a difference with the site you linked to and the code you used above:
Your code is DOS batch and uses call gswin64c .... But as said, Ghostscript cannnot expand wildcards itself.
The code in the linked web page is Unix shell, which does the wildcard expansion before Ghostscript gets to see its own commandline. When Ghostscript gets to see it, the wildcard expansion has happened already.
You have to find a solution for your batch file where you first store your (expanded) *.pdf file names in a variable %mypdfs% and then do call gswin64c ... %mypdfs%.
you can't specify the wildcard from the command line, but you can make gswin32c run a command file.
as the 'command file' just requires switches to be separated by any amount of white space (space, tab, line break), and there is no limit on the size of the file, we can make a file that does what you need
echo -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf > files.gsx
dir *.pdf /b >> files.gsx
once this file files.gsx has been created, then you can make your file using
gswin32c #files.gsx
and all the files will be merged
I did the following to solve this:
1.) dir /B *.pdf > do.bat
2.) opened do.bat with notepad to replace \r\n with spaces
3.) inserted: c:\Programs\gs\gs9.07\bin\gswin64 -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=merged.pdf at the beginning
and then executed do.bat
VoilĂ 

Ghostscript loses font while extracting the page from PDF

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 ?