![]() All of these newly created images will then have the text compressed_ added to the beginning of each filename before then being moved up a directory, out of output, and then the script will delete the now empty output directory. It will then delete any newly created file containing the text interest (for P/pinterest) or nstagram (for I/instagram) in it’s name as I don’t need either of those images resized to 750 pixels. The script will then create a temporary directory, called output, which it will then use to save a copy of each image it resized, to 750 pixels wide, and compressed, to just under 70 KB (kilobytes). If you have another directory within this one the script will not check inside of it for images. This script will go through the directory, that you passed in, and takes in all of the files ending with the following extensions: jpeg, JPEG, jpg, JPG, png, and PNG. to give it the current directory I was in: ~/D/r/P/Meal-Workout-Plans> compress_my_images.sh. Since my script still expects a pathway I passed in. Once I saved and exited I was able to go to a random directory of images and run my bash script. ![]() I opened up the file in vim, although you could use a different editor, and at the bottom of my file I added one line of text: set PATH $HOME/bin $PATH I then attempted to run the program from a different directory and it didn’t work so I had to edit my config.fish file in my. Ln -s /Users/kyra/Development/SimplyKyraBlog/compress_my_images.sh ~/bin/ The first copies the current pathway to my clipboard while the second, including the pasted pathway, creates the symbolic link: pwd | pbcopy To create the symbolic link I went to the directory my program was stored in and entered two lines. as your pathway since it means current directory. This means you can run it from the specific directory you want the program to execute on and thus you can remove the cd command, and related checks, in the script or just pass in. If you want to be able to run this program from anywhere on your computer you can set a symbolic link. One thing I need to point out about this input is that bash sees a space as the beginning of a new argument so if your pathway includes one or more spaces you’ll need to enclose it with a set of double ( ") or single ( ') quotes. I chose to start out by doing it this way as the directory I’m working in for my blog changes with each individual post. This argument is the pathway to the directory, or folder, you want to run the script against. This script, as is, only needs one argument passed in. I installed it on my computer using Homebrew through the terminal. This bash script uses the program ImageMagick ® so you’ll need to first install that before running the script. Finally, at the bottom, I’ll post my bash script in it’s entirety, all in one piece, so it’s easier for you to look over or copy, if needed, if you don’t want to use the GitHub version. Below I’ll start off by doing a quick overview followed by an in depth look at the script section by section so you understand what I did and why thus making it easier for you to alter the script for it to do what you need it to do. This saves so much time compared to when I used to do each image individually through the Preview app on my Mac. In this post I wanted to share the simple bash script I put together to allow myself to quickly resize, compress, and rename a copy of each image I want to upload to my blog. If you want more information about ImageMagick ® and how to run commands to resize, compress, or collage images together feel free to check out my previous post about this. You’re welcome to copy it at the bottom of my post or clone it through GitHub and alter it to fit your specific needs. ![]() I decided to share it with you through this post, and through GitHu b, in case you also want to use a similar script. ![]() I’ve since decided to create a bash script to make it easier to run multiple commands at once along with also renaming the newly resized and compressed image files. Earlier I posted my process on learning which commands I should use to resize and compress my images along with sharing several other points I came across along the way. This lead me to learning about ImageMagick ® so I could easily do the same tasks through the terminal. Several months ago I realized the process I use to resize and compress the images I want to upload to my blog was broken. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |