Tips and tricks

TinyPNG CLI setup to compress all files in a folder

This has only been tested on mac but should run on LINUX and WINDOWS ( power shell ) as well. We will have to create a file in your folder called minify.command

Declare array of files we will ignore ( already compressed files ) and we will transform

declare -a exclude_array
declare -a compress_array

move to your folder, and scan files

STR="`dirname $0`"
cd  $STR
yourfilenames=`ls .`
for eachfile in $yourfilenames
do
  if [[ "$eachfile" == *"compressed"* ]]
  then
  echo $eachfile
  dup=${eachfile/compressed}
  exclude_array+=($eachfile)
  exclude_array+=($dup)
  fi
done


for eachfile in $yourfilenames
do
  if [[ "$eachfile" == *".png"* ]] || [[ "$eachfile" == *".jpg"* ]] ; then
  echo $eachfile
  compress_array+=($eachfile)
  fi
done

now that we have the files and we make sure we will that we rename so that we won’t compress again redundantly

for target in "${exclude_array[@]}"; do
  for i in "${!compress_array[@]}"; do
    if [[ ${compress_array[i]} = $target ]]; then
      unset 'compress_array[i]'
    fi
  done
done


for target in "${compress_array[@]}"; do
  tinypng $target
  mv $target compressed-${target}
done
{"type":"main_options","images_arr":"'#ffffff'","enable_ajax":"off","soundcloud_apikey":"","bg_isparallax":"off","bg_slideshow_time":"0","bg_transition":"slidedown","site_url":"https:\/\/digitalzoomstudio.net","theme_url":"https:\/\/digitalzoomstudio.net\/wp-content\/themes\/qucreative\/","blur_ammount":"26","width_column":"50","width_section_bg":"","width_gap":"30","border_width":"0","border_color":"#ffffff","translate_cancel_comment":"Cancel reply","translate_leave_a_comment":"Leave a comment","translate_leave_a_comment_to":"Leave a comment to","is_customize_preview":"off","width_blur_margin":"30","gallery_w_thumbs_autoplay_videos":"off","content_enviroment_opacity":"30","menu_enviroment_opacity":"70","base_url":"https:\/\/digitalzoomstudio.net"}
{"type":"darkfull"}