├── LICENSE ├── README.md ├── polyfy └── samples ├── forest-polyfy.jpg ├── grass-polyfy.jpg ├── mountains-polyfy.jpg └── sea-polyfy.jpg /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # polyfy 2 | add cool polygons to any wallpaper 3 | 4 | #####samples: 5 | ![](https://github.com/onespaceman/polyfy/blob/master/samples/sea-polyfy.jpg) 6 | ![](https://github.com/onespaceman/polyfy/blob/master/samples/forest-polyfy.jpg) 7 | ![](https://github.com/onespaceman/polyfy/blob/master/samples/mountains-polyfy.jpg) 8 | ![](https://github.com/onespaceman/polyfy/blob/master/samples/grass-polyfy.jpg) 9 | 10 | #####about: 11 | polyfy is a bash script used to add polygons to images, mainly for the purpose of customizing desktop wallpapers. 12 | 13 | Either one or two image files may be specified. If a second image is specified, the center of the second image shall be "cut out" and inserted into the center of the polygon. 14 | 15 | By default, the output is saved in the current directory as \"[input filename]-polyfy\". 16 | This may be changed with the --output flag. If the filename that polyfy attempts to use already exists, a number shall be affixed to the end to prevent the existing file from being overwritten. 17 | 18 | #####usage: 19 | ``` 20 | chmod +x polyfy 21 | polyfy /path/to/image 22 | ``` 23 | 24 | #####options: 25 | `-h or --help` 26 | Display the instructions 27 | 28 | `--output ` 29 | Allows the output filename (and, optionally, directory) to be specified. The file extension should not be given as part of `filename`. 30 | If a directory is not specified, the file shall be saved in the current directory 31 | 32 | The default filename is the input filename suffixed with "-polyfy". 33 | The default directory is the current directory. 34 | 35 | If the filename that polyfy attempts to use already exists, a number shall 36 | be affixed to the end, starting with "2". 37 | 38 | `-r or --rotate ` 39 | Specify the rotations done on the first and second polygon. Split the degrees with a ',' 40 | 41 | `-b or --border-width ` 42 | The border width. 43 | 44 | The default value is 10. 45 | 46 | `--border-color ` 47 | The color of the border. 48 | 49 | The default value is white. 50 | 51 | `--blur ` 52 | Amount to blur the image excluding the area inside polygon. 53 | The numbers are floating point values, so you can use a very small value like '0.5'. 54 | 55 | The default value is 0. 56 | 57 | `--size ` 58 | The size of polygon as a fraction of image height. 59 | 60 | The default value is 2. 61 | 62 | `-s or --shape ` 63 | What shape should be drawn, defined by the number of sides 64 | 65 | By default the shape will be a square. 66 | 67 | `--saturate ` 68 | Amount to (de)saturate the image exluding the are inside polygon. 69 | At -100 the image is completely desaturated and at 100, completely saturated. 70 | 71 | The default value is 0. 72 | 73 | `-n or --negate ` 74 | Specify which color channels to negate. 75 | 76 | The color channels are red, green, and blue and are shortened to just the first letter: r, g, and b. Enter them without any characters or spaces between them. 77 | 78 | They can be in any combination or order like: 'g', 'bg' or 'grb'. 79 | Repeating the same channel twice cancels itself out. 80 | 81 | By default there will be no negated channels. 82 | 83 | `-o or --overlay ` 84 | Draw the second polygon over or under the first, or not at all. 85 | 86 | Type | Description 87 | -----|----- 88 | Over | Draw a second polygon over the first one 89 | Under | Draw a second polying beneath the first one 90 | None | Don't draw a second polygon 91 | 92 | The default will be 'over'. 93 | 94 | 95 | #####examples: 96 | ``` 97 | polyfy path/to/image 98 | ``` 99 | polyfy the image with the default options 100 | 101 | ``` 102 | polyfy -s 6 -n br --size 2 -b 20 /path/to/image 103 | ``` 104 | 1. polyfy with a hexagon 105 | 2. negate the blue and red channels 106 | 3. with the polygon's side length at 1/2 the image's height 107 | 4. with a border width of 20pt 108 | 109 | ``` 110 | polyfy path/to/image path/to/second/image 111 | ``` 112 | overlay a clipping from the second image onto the first image 113 | 114 | 115 | #####dependencies: 116 | [ImageMagick](http://www.imagemagick.org/) 117 | 118 | #####roadmap: 119 | * borders on polygons with an odd number of sides don't play nice with rotation 120 | -------------------------------------------------------------------------------- /polyfy: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # 3 | # Copyright (c) 2015 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | SHORT="hr:s:o:n:b:" 24 | LONG="help,rotate:,blur:,border-color:,border-width:,overlay:,size:,negate:,shape:,sides:,saturate:,output:" 25 | OPTIONS=$(getopt -o $(echo $SHORT) \ 26 | -l $(echo $LONG) \ 27 | -n "$0" \ 28 | -- "$@") 29 | 30 | eval set -- "$OPTIONS" 31 | 32 | # Default variables 33 | num_sides="4" #default polygon 34 | overlay="over" #default drawing option for the second polygon 35 | border_w="10" #default border width 36 | border_c="white" #default border color 37 | size="2" #default size of polygon 38 | rotation_f="0" 39 | rotation_s="0" 40 | dup_c=2 41 | 42 | while true; do 43 | case "$1" in 44 | -n|--negate) 45 | # TODO: Elegant of not parsing the -channel and -negate when there's 46 | # other characters specified apart from 'rgb'. 47 | negate="-channel ${2//[^rgb]/} -negate" 48 | shift 2 ;; 49 | -r|--rotate) 50 | rotation_f="${2%,*}" 51 | rotation_s="${2#*,}" 52 | shift 2 ;; 53 | -o|--overlay) 54 | overlay="$2" 55 | shift 2 ;; 56 | --blur) 57 | blur="-blur 0x$2" 58 | shift 2 ;; 59 | --size) 60 | size="$2" 61 | shift 2 ;; 62 | --saturate) 63 | saturation="$2" 64 | saturate="-modulate 100,$((saturation+100))" 65 | shift 2;; 66 | --output) 67 | output="$2" 68 | shift 2 ;; 69 | -s|--shape|--sides) 70 | num_sides="$2" 71 | shift 2 ;; 72 | -b|--border-width) 73 | border_w="$2" 74 | shift 2 ;; 75 | --border-color) 76 | border_c="$2" 77 | shift 2 ;; 78 | -h|--help) 79 | echo " 80 | $(tput bold)NAME$(tput sgr0) 81 | Polyfy - Add cool polygons to any wallpaper 82 | 83 | $(tput bold)SYNOPSIS$(tput sgr0) 84 | $(tput bold)polyfy$(tput sgr0) [option$(tput sgr0)]... $(tput sitm)file$(tput sgr0) [$(tput sitm)second file$(tput sgr0)] 85 | 86 | $(tput bold)DESCRIPTION$(tput sgr0) 87 | $(tput bold)polyfy$(tput sgr0) is a bash script used to add polygons to images, mainly for the 88 | purpose of customizing desktop wallpapers. 89 | 90 | Either one or two image files may be specified. If a second image is specified, the 91 | center of the second image shall be "cut out" and inserted into the center 92 | of the polygon. 93 | 94 | By default, the output is saved in the current directory as \"[input filename]-polyfy\". 95 | This may be changed with the --output flag. If the filename that $(tput bold)polyfy$(tput sgr0) attempts to use 96 | already exists, a number shall be affixed to the end to prevent the existing file from 97 | being overwritten. 98 | 99 | $(tput bold)polyfy$(tput sgr0) is hosted at https://github.com/onespaceman/polyfy 100 | 101 | $(tput bold)OPTIONS$(tput sgr0) 102 | $(tput bold)-h, --help $(tput sgr0) 103 | You're looking at it. 104 | 105 | $(tput bold)--output$(tput sgr0) 106 | Allows the output filename (and, optionally, directory) to be specified. The file 107 | extension should not be given as part of \`filename\`. 108 | If a directory is not specified, the file shall be saved in the current directory. 109 | 110 | $(tput bold)-r, --rotate$(tput sgr0) , 111 | Specify the rotations done on the first and second polygon. Split the 112 | degrees with a ',' 113 | 114 | $(tput bold)-b, --border-width$(tput sgr0) 115 | The border width. 116 | 117 | The default value is 10. 118 | 119 | $(tput bold)--border-color$(tput sgr0) 120 | The color of the border. 121 | 122 | The default value is white. 123 | 124 | $(tput bold)--blur$(tput sgr0) 125 | Amount to blur the image excluding the area inside polygon. 126 | The numbers are floating point values, so you can use a very small 127 | value like '0.5'. 128 | 129 | The default value is 0. 130 | 131 | $(tput bold)--size$(tput sgr0) 132 | The size of the polygon as a fraction of image height. 133 | 134 | The default value is 2. 135 | 136 | $(tput bold)-s, --shape, --sides$(tput sgr0) 137 | What shape should be drawn, defined by the number of sides 138 | 139 | By default the shape will be a square. 140 | 141 | $(tput bold)--saturate$(tput sgr0) 142 | Amount to (de)saturate the image exluding the are inside polygon. 143 | At -100 the image is completely desaturated and at 100, completely saturated. 144 | 145 | The default value is 0. 146 | 147 | $(tput bold)-n, --negate$(tput sgr0) 148 | Specify which color channels to negate. 149 | 150 | The color channels are red, green, and blue and are shortened to just the 151 | first letter: r, g, and b. Enter them without any characters or spaces 152 | between them. 153 | 154 | They can be in any combination or order like: 'g', 'bg' or 'grb'. 155 | Repeating the same channel twice cancels itself out. 156 | 157 | By default there will be no negated channels. 158 | 159 | $(tput bold)-o, --overlay$(tput sgr0) 160 | Draw the second polygon over or under the first, or not at all. 161 | 162 | | Type | Description | 163 | |-------------------------------------------------------| 164 | | Under | Draw a second polying beneath the first one | 165 | | Over | Draw a second polygon over the first one | 166 | | None | Don't draw a second polygon | 167 | 168 | The default will be 'over'. 169 | 170 | $(tput bold)EXAMPLES$(tput sgr0) 171 | polyfy the image with the default options: 172 | 173 | polyfy path/to/image 174 | 175 | polyfy with a hexagon, negate the blue and red channels, set the 176 | polygon's side length to 1/2 the image's height, and set the polygon's 177 | border width to 20 pixels: 178 | 179 | polyfy -s 6 -n br --size 2 -b 20 /path/to/image 180 | 181 | overlay a clipping from the second image onto the first image: 182 | 183 | polyfy /path/to/image /path/to/second/image 184 | " 185 | exit ;; 186 | --) shift 187 | break ;; 188 | * ) break ;; 189 | esac 190 | done 191 | 192 | [[ -f ${1} ]] && { 193 | file_f="${1//~/$HOME}"; shift 194 | [[ -f ${1} ]] && { 195 | file_s="${1//~/$HOME}"; shift 196 | } || { 197 | file_s=$file_f 198 | } 199 | } || { 200 | echo "You did not specify a file." 201 | exit 0 202 | } 203 | directory=$(dirname $file_f) 204 | filename=$(basename ${file_f%.*}) 205 | image_h=$(identify -format "%h" $file_f) 206 | image_w=$(identify -format "%w" $file_f) 207 | format=$(basename ${file_f##*.}) 208 | dup_c="" 209 | 210 | if [[ -z $output ]]; then 211 | [[ -e $directory/$filename-polyfy.$format ]] && { 212 | dup_c=2 213 | while [[ -e $directory/$filename-polyfy"$dup_c".$format ]]; do 214 | let dup_c++ 215 | done 216 | } 217 | filename="$directory/$filename-polyfy"$dup_c".$format" 218 | else 219 | directory=$(dirname $output) 220 | filename=$(basename ${output%.%}) 221 | [[ -e $directory/$filename.$format ]] && { 222 | dup_c=2 223 | while [[ -e $directory/$filename"$dup_c".$format ]]; do 224 | let dup_c++ 225 | done 226 | } 227 | filename="$directory/$filename"$dup_c".$format" 228 | fi 229 | 230 | #calculate the path of the given shape 231 | length=$(echo "$image_h / $size" | bc -l | awk '{print int($1 + 0.5)}') 232 | center_x=$(echo "$length / 2" | bc -l) 233 | #the radius 234 | radius=$(echo "($length - $border_w) / 2" | bc -l) 235 | pi=$(echo "scale=10; 4 * a(1)" | bc -l) 236 | 237 | #align the shape to be vertically symetrical 238 | if [ $((num_sides%2)) -eq 0 ]; then 239 | align_shape="1" 240 | rotate_s=$(echo "180 / $num_sides" | bc -l | awk '{print int ($1 + 0.5)}') 241 | else 242 | align_shape="0.5" 243 | rotate_s="180" 244 | fi 245 | 246 | degrees=$(echo "180 / $num_sides * $align_shape" | bc -l) 247 | theta=$(echo "$pi / 180 * $degrees" | bc -l) 248 | 249 | #calculate vertices and place in arrays 250 | for ((i=0;i