The utility "xli" is used to render an image on the root window.
xli is executed from within /root/.xinitrc when X starts.
There is also a script for choosing the background image; /usr/sbin/set-bkgrnd.
PROBLEM:
For certain combinations of screen resolution and image dimensions, we get the image rendered with white/black space on the sides of the image.
SOLUTION:
Automatically resize the image to match the screen dimensions.
xli itself is capable of doing this. It has "-zoomx" and "-zoomy" options, but the problem is they are expressed as a percentage, whereas we need exact pixel dimensions. ...a script could perform some calculation to work out the percentage.
Anyway, there could be a little script, maybe built into set-bkgrnd. that resizes the chosen image. Or it could be done in .xinitrc.
But, how to read an image dimensions from the commandline?
Project suggestion: fix proportions of background image
Code: Select all
#!/usr/bin/puppybasic
include "/usr/lib/wxbasicscript/basefunctions.inc"
' PB-Back
' calculates best quality-settings for xli
pic = argvtostring()
if pic = "" then
print "usage: PB-Back <imagefilename>"
end
end if
shell( "xli -identify \"" & pic & "\" >/tmp/PB-Back.tmp" )
picinfo = readfile( "/tmp/PB-Back.tmp" )
picinfo = cutleft( picinfo , "is a ")
picinfo = cutrightfromleft( picinfo , " ")
picwidth = cutright( picinfo , "x")
picheight = cutleft( picinfo , "x")
screensize = xwin_screensize()
screenwidth = screensize[0]
screenheight = screensize[1]
percentheight = (screenheight / picheight ) * 100
percentwidth = (screenwidth / picwidth ) * 100
'shell ( "xli -onroot -colordither -colors 256 -smooth -xzoom " & percentwidth & " -yzoom " & percentheight & " \"" & pic & "\"")
shell ( "xli -onroot -smooth -colordither -xzoom " & percentwidth & " -yzoom " & percentheight & " \"" & pic & "\"")
'print "scaling image x:"& percentwidth & "% y:" & percentheight & "%"
removefile( "/tmp/PB-Back.tmp" )
Last edited by MU on Sun 04 Dec 2005, 06:59, edited 3 times in total.
It creates quite good results.
The relatively small image:
http://dotpups.de/pics/puppy/PB-Back/PB-Back2.jpg
Set as Background:
http://dotpups.de/pics/puppy/PB-Back/PB-Back1.jpg
here I added -colors 256 to xli to simulate a 256-color-Display:
http://dotpups.de/pics/puppy/PB-Back/PB-Back3.jpg
Mark
The relatively small image:
http://dotpups.de/pics/puppy/PB-Back/PB-Back2.jpg
Set as Background:
http://dotpups.de/pics/puppy/PB-Back/PB-Back1.jpg
here I added -colors 256 to xli to simulate a 256-color-Display:
http://dotpups.de/pics/puppy/PB-Back/PB-Back3.jpg
Mark
Barry, I made a small enhancement.
-smooth just makes sense, if the picture is scaled.
If it has the same size as the monitor, it looks less "blured" without smoothing.
So this version checks that.
mark
-smooth just makes sense, if the picture is scaled.
If it has the same size as the monitor, it looks less "blured" without smoothing.
So this version checks that.
Code: Select all
#!/usr/bin/puppybasic
include "/usr/lib/wxbasicscript/basefunctions.inc"
' PB-Back
' calculates best quality-settings for xli
pic = argvtostring()
if pic = "" then
print "usage: PB-Back <imagefilename>"
end
end if
shell( "xli -identify \"" & pic & "\" >/tmp/PB-Back.tmp" )
picinfo = readfile( "/tmp/PB-Back.tmp" )
picinfo = cutleft( picinfo , "is a ")
picinfo = cutrightfromleft( picinfo , " ")
picwidth = cutright( picinfo , "x")
picheight = cutleft( picinfo , "x")
screensize = xwin_screensize()
screenwidth = screensize[0]
screenheight = screensize[1]
percentheight = (screenheight / picheight ) * 100
percentwidth = (screenwidth / picwidth ) * 100
smooth = ""
if screenwidth != picwidth then
smooth = " -smooth "
end if
if screenheight != picheight then
smooth = " -smooth "
end if
'shell ( "xli -onroot " & smooth & " -colors 256 -colordither -xzoom " & percentwidth & " -yzoom " & percentheight & " \"" & pic & "\"")
shell ( "xli -onroot " & smooth & " -colordither -xzoom " & percentwidth & " -yzoom " & percentheight & " \"" & pic & "\"")
'print "scaling image x:"& percentwidth & "% y:" & percentheight & "%"
removefile( "/tmp/PB-Back.tmp" )