I wonder if it is possible to remove the background from an image and
make it transparent using Tk or a package? Then I can save it as a png image. The background in my case consists of a single color. Perhaps I
could replace that color with an "alpha" color but how?
saito <saitology9@gmail.com> wrote:
I wonder if it is possible to remove the background from an image and
make it transparent using Tk or a package? Then I can save it as a png
image. The background in my case consists of a single color. Perhaps I
could replace that color with an "alpha" color but how?
man n photo:
imageName transparency subcommand ?arg arg ...?
Allows examination and manipulation of the transparency
information in the photo image. Several subcommands are
available:
I wonder if it is possible to remove the background from an image and make it transparent using Tk or a package? Then I can save it as a png image. The background in my case consists of a single color. Perhaps I could replace that color with an "alpha" color but how?
imageName transparency set x y boolean
Makes the pixel at (x,y) transparent if boolean is true,
and makes that pixel opaque otherwise.
proc SetTransparentColor { phImg { red 255 } { green 255 } { blue 255 } } {
set colorStr [format "#%02x%02x%02x" $red $green $blue]
set y 0
foreach row [$phImg data] {
set x 0
foreach pixel $row {
if { $colorStr eq $pixel } {
$phImg transparency set $x $y 1
}
incr x
}
incr y
}
}
Paul
On 10/17/2024 3:35 PM, Rich wrote:
saito <saitology9@gmail.com> wrote:
I wonder if it is possible to remove the background from an image and
make it transparent using Tk or a package? Then I can save it as a png
image. The background in my case consists of a single color. Perhaps I
could replace that color with an "alpha" color but how?
man n photo:
imageName transparency subcommand ?arg arg ...?
Allows examination and manipulation of the transparency
information in the photo image. Several subcommands are
available:
Thank you - I missed this page. Does this command apply to non-png
images?
Initially the image will have no transparency, since the
background is a solid, opaque color?
The challenge in my case is I don't know where the background starts and what color it would be. The latter can be solved by involving the user perhaps.
Thank you - I missed this page. Does this command apply to non-png
images?
It applies to all Tk photo images.
Whether you can save the transparency to a file will depend upon the
file format you choose to save the result into.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (0 / 10) |
Uptime: | 119:21:30 |
Calls: | 12,958 |
Files: | 186,574 |
Messages: | 3,265,634 |