Project suggestion: fix proportions of background image

Under development: PCMCIA, wireless, etc.
Post Reply
Message
Author
User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

Project suggestion: fix proportions of background image

#1 Post by BarryK »

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?

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#2 Post by GuestToo »

i think the only background-setting shell commands in .xinitrc should be 1 line that calls the appropriate scripts

maybe something like sh /etc/background &

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#3 Post by GuestToo »

how to read an image dimensions from the commandline?
maybe something like

xli -identify *.png | awk '{print $4}'

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#4 Post by MU »

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" )

Greets, Mark
Last edited by MU on Sun 04 Dec 2005, 06:59, edited 3 times in total.

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#5 Post by MU »

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

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#6 Post by BarryK »

Incredible!

I'll check it out tonight, see how to incorporate it into 1.0.7alpha.

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#7 Post by MU »

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.

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" )
mark

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#8 Post by BarryK »

Mark,
Ok, will do.

Note, it's already announced on the News page,
www.puppylinux.com/news.htm

Post Reply