Hi folks !
For my personal use I wrote a Lua script used to transform square image to "rounded" image (ie circle with transparency).
I also wrote a script to get images from Moon or from Earth...
From this image to this one (in a conky)
First, the script to get the moon or earth image : get_moon_earth.sh (to get the moon you need to pass moon as parameter). The parameters at the beginning of the script are the same as on this page : http://www.fourmilab.ch/earthview/expert.html
Code:
#!/bin/bash
#This script download image from Earth or from Moon (if first parameter = "moon")
#the parameters are the sames as on this page
#http://www.fourmilab.ch/earthview/expert.html
#version1.0, wlourf 07 avril 2010
#http://u-scripts.blogspot.com/
#===========début des paramètres===============
dir="/tmp/earth"
if [[ "$1" == "moon" ]]; then
Latitude=46 #number
NorthSouth=n #n/s
Longitude=0 #number
EastWest=e #e/w
Altitude=401725 #altitude in kilometers (max=401725)
#___Image___
Image=topo #topo,albedo
Size=320 #number (default=320)
ShowNight=true #true/false
file1=$dir/get_moon.txt #temp file for url
file2=$dir/moon_image #final image
else
#___View___
Latitude=33 #number
NorthSouth=n #n/s
Longitude=70 #number
EastWest=e #e/w
Altitude=35785 #altitude in kilometers (max=35785)
#___Image___
Image=live #live,marble,nasa,topo,cloudy,ir,cweather,vapour_bg,vapour
Size=320 #number (default=320)
ShowNight=true #true/false
file1=$dir/get_earth.txt #temp file for url
file2=$dir/earth_image #final image
fi
#===========fin des paramètres===============
base=http://www.fourmilab.ch
#mise en forme des paramètres
if [[ "$NorthSouth" == "s" ]]; then
NorthSouth="South"
else
NorthSouth="North"
fi
if [[ "$EastWest" == "e" ]]; then
EastWest="East"
else
EastWest="West"
fi
if [[ "$ShowNight" == true ]]; then
DayNight=""
else
DayNight="&daynight=d"
fi
if [[ "$1" == "moon" ]]; then
case $Image in
"topo") Image="MoonTopo.evif";;
*) Image="Moon.evif";;
esac
else
case $Image in
"marble") Image="NASA500m.evif";;
"nasa") Image="nasa.evif";;
"topo") Image="NOAAtopo.evif";;
"clouds") Image="cloudy.bmp";;
"ir") Image="irsat.bmp";;
"cweather") Image="wx-cmap.bmp";;
"vapour_bg")Image="vapour_bg.bmp";;
"vapour") Image="vapour.bmp";;
*) Image="learth.evif";;
esac
fi
#get the url
mkdir -p $dir
cd $dir
GET http://www.fourmilab.ch/cgi-bin/Earth?lat=$Latitude\&ns=l$NorthSouth\&lon=$Longitude\&ew=$EastWest\&alt=$Altitude$DayNight\&img=$Image\&imgsize=$Size > $file1
#extract the line of the image
match="<img src="
url_line=""
while read line
do
if [[ "$line" =~ "${match}" ]]; then
url_line=$line
break
fi
done < $file1
if [[ "$url_line" == "" ]]; then
echo "no url matched"
exit
fi
#extract the link of the image and save the image
begin="<img src=\""
end="\" ismap"
a=$(($(expr "$url_line" : ".*$begin")))
b=$(($(expr "$url_line" : ".*$end")-$a-${#end}))
url_image=${url_line:$a:$b}
GET $base$url_image > $file2
exit
The Lua script square_to_round.lua :
Code:
--[[ SQUARE_TO_ROUND WIDGET by Wlourf (07 April 2010, version 1.0.1)
http://u-scripts.blogspot.com/
This widget display a rounded image on your conky from a square image only.
Parameters are
filename --name of picture to use
xc,yc --coordinates of the center of circle relative to top left corner of conky window
radius --radius of the circle
angle --angle of rotation in degrees
radius_crop --percentage of original image to keep (0-100)
period --convert input image to output image every 'period' seconds
]]
require 'cairo'
require 'imlib2'
function convert_square(fileIn,fileOut,radius,angle,radius_crop)
--convert Input file from jpg to png, scale it and rotate it
local imageInput = imlib_load_image(fileIn)
local out_size = radius*2/(radius_crop/100)
imlib_context_set_image(imageInput)
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_image_set_format("png")
buffer = imlib_create_image(out_size,out_size);
imlib_context_set_image(buffer);
imlib_blend_image_onto_image(imageInput, 0,
0, 0, w, h,
0,0, out_size,out_size)
rot_img=imlib_create_rotated_image(angle*math.pi/180)
imlib_context_set_image(rot_img)
imlib_save_image(fileOut)
imlib_free_image()
imlib_context_set_image(buffer)
imlib_free_image()
imlib_context_set_image(imageInput)
imlib_free_image()
end
function crop_square_to_round(filename,xc,yc,radius)
local surface = cairo_image_surface_create_from_png(filename)
local img_w = cairo_image_surface_get_width (surface);
local cw,ch = conky_window.width, conky_window.height
local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, cw,ch)
local cr=cairo_create(cs)
cairo_translate(cr,xc-img_w/2,yc-img_w/2)
cairo_arc (cr, img_w/2,img_w/2, radius, 0, 2*math.pi)
cairo_clip (cr)
cairo_new_path (cr)
cairo_set_source_surface (cr, surface, 0, 0)
cairo_paint (cr)
cairo_destroy(cr)
cairo_surface_destroy (cs)
cairo_surface_destroy (surface)
end
function display_round(filename,xc,yc,radius,angle,radius_crop,period)
if conky_window == nil then return end
if tonumber(conky_parse('${updates}')) <2 then return end
local filepng = filename .. ".png"
local actual_time = os.time()
if last_time == nil then last_time=0 end
local actual_img = io.open(filepng,"r")
if last_time+period < actual_time or last_time == 0 or actual_img == nil then
print ('convert image ' .. filename)
convert_square(filename,filepng,radius,angle,radius_crop)
last_time=actual_time
end
crop_square_to_round(filepng,xc,yc,radius)
io.close()
end
--[[END OF SQUARE TO ROUND WIDGET]]
function conky_main(filename)
if conky_window == nil then return end
display_round(filename,
275,275,120, --xc,yc,radius
5, --angle
98, --radius_crop (1-100)
3600 --period
)
end
And the conkyrc
Code:
# -- Conky settings -- #
background no
update_interval 10
cpu_avg_samples 2
net_avg_samples 2
override_utf8_locale yes
double_buffer yes
no_buffers yes
text_buffer_size 2048
imlib_cache_size 0
# -- Window specifications -- #
own_window yes
#own_window_type normal
own_window_transparent yes
#own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
own_window_colour FFFFFF
own_window_title square to round
border_inner_margin 0
border_outer_margin 0
minimum_size 450 550
alignment tm
gap_y 0
gap_x 0
# -- Graphics settings -- #
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
# -- Text settings -- #
use_xft yes
xftfont Santana:size=12
xftalpha 0
uppercase no
default_color 000000
text_buffer_size 2048
imlib_cache_size 0
#--- LUA ---
lua_load ~/wip/earth/square_to_round.lua
#first parameter is the square image to use
lua_draw_hook_pre main /tmp/earth/earth_image
TEXT
${execpi 3600 ~/wip/earth/get_moon_earth.sh earth}
And if you are inspired, you can get amazing conkys like this one :
Happy conkying
EDIT : a more simple way to have rounded images is here, with a script from larryni : http://wwww.ubuntuforums.org/showpos...ostcount=13076
You need the 2 masks from the above topic.
I use it now in my script, so it gives that :
Code:
#!/bin/bash
#This script download image from Earth or from Moon (if first parameter = "moon")
#the parameters are the sames as on this page
#http://www.fourmilab.ch/earthview/expert.html
#version1.1, wlourf 14 sept. 2010
#http://u-scripts.blogspot.com/
#http://ubuntuforums.org/showpost.php?p=9088516&postcount=244
#http://ubuntuforums.org/showpost.php?p=8117609&postcount=9846
#http://wwww.ubuntuforums.org/showpost.php?p=9541241&postcount=13076
#first parameter moon to display moon, other or mssing = earth
#===========début des paramètres===============
dir="/tmp/earth"
dirmasks="/home/ll/conky/earth"
if [[ "$1" == "moon" ]]; then
Latitude=47.243055556 #number
NorthSouth=n #n/s
Longitude=6.021944444 #number
EastWest=e #e/w
Altitude=401725 #altitude in kilometers (max=401725)
#___Image___
Image=topo #topo,albedo
Size=100 #number (default=320)
ShowNight=true #true/false
file1=$dir/get_moon.txt #temp file for url
file2=$dir/moon_image #final image
basename="moon"
else
#___View___
Latitude=47.243055556 #number
NorthSouth=n #n/s
Longitude=6.021944444 #number
EastWest=e #e/w
Altitude=35785 #altitude in kilometers (max=35785)
#___Image___
Image=live #live,marble,nasa,topo,cloudy,ir,cweather,vapour_bg,vapour
Size=100 #number (default=320)
ShowNight=true #true/false
file1=$dir/get_earth.txt #temp file for url
file2=$dir/earth_image #final image
basename="earth"
fi
#===========fin des paramètres===============
base=http://www.fourmilab.ch
#mise en forme des paramètres
if [[ "$NorthSouth" == "s" ]]; then
NorthSouth="South"
else
NorthSouth="North"
fi
if [[ "$EastWest" == "e" ]]; then
EastWest="East"
else
EastWest="West"
fi
if [[ "$ShowNight" == true ]]; then
DayNight=""
else
DayNight="&daynight=d"
fi
if [[ "$1" == "moon" ]]; then
case $Image in
"topo") Image="MoonTopo.evif";;
*) Image="Moon.evif";;
esac
else
case $Image in
"marble") Image="NASA500m.evif";;
"nasa") Image="nasa.evif";;
"topo") Image="NOAAtopo.evif";;
"clouds") Image="cloudy.bmp";;
"ir") Image="irsat.bmp";;
"cweather") Image="wx-cmap.bmp";;
"vapour_bg")Image="vapour_bg.bmp";;
"vapour") Image="vapour.bmp";;
*) Image="learth.evif";;
esac
fi
#get the url
mkdir -p $dir
cd $dir
wget -q http://www.fourmilab.ch/cgi-bin/Earth?lat=$Latitude\&ns=l$NorthSouth\&lon=$Longitude\&ew=$EastWest\&alt=$Altitude$DayNight\&img=$Image\&imgsize=$Size -O $file1
#extract the line of the image
url_image="$(cat $file1 | grep "<img src=" | awk -F'\"' '{print $2}' )"
if [[ "$url_image" == "" ]]; then
echo "no url matched"
exit
fi
#extract the link of the image and save the image
wget -q $base$url_image -O $file2
convert $file2 -colorspace Gray $dirmasks/overlay$Size.png -compose HardLight -composite $dirmasks/mask$Size.png -alpha off -compose CopyOpacity -composite $dir/$basename-out.png
#convert $file2 -colorspace Gray $dirmasks/mask$Size.png -alpha off -compose CopyOpacity -composite $dir/$basename-out.png
exit 0
Bookmarks