#!/bin/bash # # cylinder_bar [percent [image]] # # Create a Cylindrical Percentage Bar and Label # # Method makes use of a shading overlay to generate more realisitic # glass effects, especially at the ends of the 'glass' cylinder. # It uses a drawn layers approach. # * White background layer (also providing the shape for later shadows) # * Draw over with green 3D cylinder of the right lenght # * Overlaid with a Transparent shaded glass effect. # * Final edge drawing of the glass cylinder # * Shadow effects of the whole result # * A shadowed label, generated and appended as a separate image # #### # # Anthony Thyssen 30 November 2010 # # Using a technique for generating cylinders using rounded rectangles # originally demonstrated by "Totor" on ImageMagick Users Forum... # http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&p=66100 # # Warning this makes use of some fancy BASH shell script methods running # sub-processes to generating the draw commands read into the primary command # via bash inline named pipes. That is the construct "<(...)" is replaced by a # named pipe, which is basically like a temporary file containing either drawing # commands which were echo'ed, or a generated image. Very tricky # percent="${1:-"50"}" width=320 height=100 offset=10 # offset from edges, large enough to hold shadow thickness=2 # glass thickness betwwn outside and colored inside cylinder # The bar colors (before glass shading) bar_color1=lime bar_color2=green bar_color3=green2 # end cap color (before glass shading) background=White # The final background color to use (can be "none") # Alternatives: Lavendar, Gainsboro, LemonChiffon # Now calculate the other constants of the cyliner from the above. glass_radius=$((height/2-offset)) # 40 glass_endcap=$((glass_radius/2)) # 20 glass_length=$((width-glass_radius-2*offset)) # 260 - excludes endcaps bar_radius=$((glass_radius-2*thickness)) bar_endcap=$((bar_radius/2)) bar_length=$((glass_length*percent/100)) draw_base() { # This command is basically one enormouse 'echo' but is designed # so that when used with <(...) BASH will read it as if it # was comming from a external file of MVG image file cat<