![]() #!/bin/bashįor img in $( find $input_dir -type f -iname "*.webp" ) Let’s start by writing a script called webp2png.sh, which pretty much says what it does: convert WebP files to PNG files. We will convert three types of images into PNG in this tutorial: WebP, JPEG, and SVG. ![]() Now that our images are organized, we can move onto creating variants of each image. Let’s run it! bash organize-images.sh original-images Finally, it creates subdirectories in the input folder for each MIME type and drops a copy of each image into their respective sub-directory. the script then goes into that input directory, looks for image files and identifies their MIME type. ![]() We give the script an input directory where it looks for images. This might look confusing if you’re new to writing scripts, but what it’s doing is actually pretty simple. Img_type=$(basename `file -mime-type -b $img`) The following code creates a script called organize-images.sh: #!/bin/bashĮcho "Please specify an input directory."įor img in $( find $input_dir -type f -iname "*" ) In fact, we can create a new bash to do that for us! Let’s organize them by splitting them up into different sub-directories based on their MIME type. But before we jump into optimizing all the things, we should organize our files a bit. So back anything up that you plan to use on a real project to prevent cursing yourself later. We’re about to run programs that alter these images, and while we plan to leave the originals alone, one wrong command might change them in some irreversible way. Note: It is strongly recommended to backup your images before proceeding. OK, we have our images in the original-images directory from the GitHub repo.
0 Comments
Leave a Reply. |