Diff
diff --git a/cstyle/transformers/image/main.go b/cstyle/transformers/image/main.go
index 9701cd0..73b01b7 100644
--- a/cstyle/transformers/image/main.go
+++ b/cstyle/transformers/image/main.go
@@ -4 +4 @@ import (
- // "bytes"
+ "bytes"
@@ -7,6 +7,6 @@ import (
- // "image"
- // _ "image/gif" // Enable GIF support
- // _ "image/jpeg" // Enable JPEG support
- // _ "image/png" // Enable PNG support
- // "path/filepath"
- // "strconv"
+ "image"
+ _ "image/gif" // Enable GIF support
+ _ "image/jpeg" // Enable JPEG support
+ _ "image/png" // Enable PNG support
+ "path/filepath"
+ "strconv"
@@ -23,35 +23,34 @@ func Init() cstyle.Transformer {
- // res, exists := c.Adapter.Textures[n.Properties.Id]["background"]
- // if !exists {
- // i, err := c.Adapter.FileSystem.ReadFile(filepath.Join(c.Path, n.Src))
- // if err == nil {
- // img, _, err := image.Decode(bytes.NewReader(i))
- // if err == nil {
- // width, height := n.ComputedStyle["width"], n.ComputedStyle["height"]
- // if n.ComputedStyle["width"] == "" {
- // width = strconv.Itoa(img.Bounds().Dx()) + "px"
- // }
- // if n.ComputedStyle["height"] == "" {
- // height = strconv.Itoa(img.Bounds().Dy()) + "px"
- // }
- // ctx := n.GetContext(img.Bounds().Dx(), img.Bounds().Dy())
- // n.ComputedStyle["width"] = width
- // n.ComputedStyle["height"] = height
- // ctx.DrawImage(img, 0, 0)
- // }
- // }
- // } else {
- // img, _ := c.Adapter.Library.Get(n.Properties.Id + "canvas")
- // width, height := n.ComputedStyle["width"], n.ComputedStyle["height"]
- // if width == "" {
- // width = strconv.Itoa(img.Bounds().Dx()) + "px"
- // }
- // if height == "" {
- // height = strconv.Itoa(img.Bounds().Dy()) + "px"
- // }
- // // !ISSUE: Doesn't resize and uses a lot of memory (nah its the top)
- // // + here resize the image then store it, then just add the key to the state.Textures
- // ctx := n.GetContext(img.Bounds().Dx(), img.Bounds().Dy())
- // n.ComputedStyle["width"] = width
- // n.ComputedStyle["height"] = height
- // ctx.DrawImage(img, 0, 0)
- // }
+ if !c.Adapter.Library.Check(n.Properties.Id + "canvas") {
+ i, err := c.Adapter.FileSystem.ReadFile(filepath.Join(c.Path, n.Src))
+ if err == nil {
+ img, _, err := image.Decode(bytes.NewReader(i))
+ if err == nil {
+ width, height := n.ComputedStyle["width"], n.ComputedStyle["height"]
+ if n.ComputedStyle["width"] == "" {
+ width = strconv.Itoa(img.Bounds().Dx()) + "px"
+ }
+ if n.ComputedStyle["height"] == "" {
+ height = strconv.Itoa(img.Bounds().Dy()) + "px"
+ }
+ ctx := n.GetContext(img.Bounds().Dx(), img.Bounds().Dy())
+ n.ComputedStyle["width"] = width
+ n.ComputedStyle["height"] = height
+ ctx.DrawImage(img, 0, 0)
+ }
+ }
+ } else {
+ img, _ := c.Adapter.Library.Get(n.Properties.Id + "canvas")
+ width, height := n.ComputedStyle["width"], n.ComputedStyle["height"]
+ if width == "" {
+ width = strconv.Itoa(img.Bounds().Dx()) + "px"
+ }
+ if height == "" {
+ height = strconv.Itoa(img.Bounds().Dy()) + "px"
+ }
+ // !ISSUE: Doesn't resize and uses a lot of memory (nah its the top)
+ // + here resize the image then store it, then just add the key to the state.Textures
+ ctx := n.GetContext(img.Bounds().Dx(), img.Bounds().Dy())
+ n.ComputedStyle["width"] = width
+ n.ComputedStyle["height"] = height
+ ctx.DrawImage(img, 0, 0)
+ }