### Install Aseprite Loader Package - Go Source: https://github.com/askeladdk/aseprite/blob/master/README.md Installs the aseprite image loader package using the Go build tool. This command fetches the latest version of the package and makes it available for import in your Go projects. ```go go get -u github.com/askeladdk/aseprite ``` -------------------------------- ### Decode Aseprite Configuration Without Full Image Data Source: https://context7.com/askeladdk/aseprite/llms.txt Retrieves the configuration (dimensions and color model) of an Aseprite file without loading all pixel data, optimizing for cases where only metadata is needed. This uses the standard Go 'image' package and requires the Aseprite format to be registered, typically via an import like `_ "github.com/askeladdk/aseprite"`. ```go package main import ( "image" "image/color" "log" "os" _ "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("large_sprite.aseprite") if err != nil { log.Fatal(err) } defer file.Close() config, format, err := image.DecodeConfig(file) if err != nil { log.Fatal(err) } if format != "aseprite" { log.Fatalf("unexpected format: %s", format) } log.Printf("Atlas dimensions: %dx%d", config.Width, config.Height) // Check color model type switch config.ColorModel { case color.RGBAModel: log.Println("Color mode: RGBA (32-bit)") case color.Gray16Model: log.Println("Color mode: Grayscale (16-bit)") default: if _, ok := config.ColorModel.(color.Palette); ok { log.Println("Color mode: Indexed (8-bit)") } } } ``` -------------------------------- ### Access Aseprite Slices for UI and 9-Patch Source: https://context7.com/askeladdk/aseprite/llms.txt Accesses and logs information about slices within an Aseprite file, including names, bounds, 9-patch center regions, pivot points, colors, and user data. This is useful for UI elements and scalable graphics. It depends on the 'github.com/askeladdk/aseprite' library. ```go package main import ( "image" "log" "os" "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("ui_elements.aseprite") if err != nil { log.Fatal(err) } defer file.Close() sprite, err := aseprite.Read(file) if err != nil { log.Fatal(err) } // Process slices for UI elements for _, slice := range sprite.Slices { log.Printf("Slice: %s", slice.Name) log.Printf(" Bounds: %v", slice.Bounds) // Check if this is a 9-patch slice if !slice.Center.Empty() { log.Printf(" 9-patch center: %v", slice.Center) log.Printf(" Top-left corner: %dx%d", slice.Center.Min.X-slice.Bounds.Min.X, slice.Center.Min.Y-slice.Bounds.Min.Y) log.Printf(" Bottom-right corner: %dx%d", slice.Bounds.Max.X-slice.Center.Max.X, slice.Bounds.Max.Y-slice.Center.Max.Y) } // Check for pivot point if slice.Pivot != (image.Point{}) { log.Printf(" Pivot: %v", slice.Pivot) } // Access slice color and user data if slice.Color != nil { r, g, b, a := slice.Color.RGBA() log.Printf(" Color: rgba(%d, %d, %d, %d)", r>>8, g>>8, b>>8, a>>8) } if len(slice.Data) > 0 { log.Printf(" User data: %s", string(slice.Data)) } } } ``` -------------------------------- ### Access Aseprite Animation Tags and Loop Directions (Go) Source: https://context7.com/askeladdk/aseprite/llms.txt Demonstrates how to extract and interpret animation tags from an Aseprite file. This code iterates through the `Tags` field of the `Aseprite` struct, accessing animation names, frame ranges, loop directions (forward, reverse, ping-pong), and repeat counts. It also calculates the total duration for each animation sequence. ```go package main import ( "fmt" "log" "os" "time" "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("character.aseprite") if err != nil { log.Fatal(err) } defer file.Close() sprite, err := aseprite.Read(file) if err != nil { log.Fatal(err) } // Process each animation tag for _, tag := range sprite.Tags { var loopType string switch tag.LoopDirection { case aseprite.Forward: loopType = "forward" case aseprite.Reverse: loopType = "reverse" case aseprite.PingPong: loopType = "ping-pong" case aseprite.PingPongReverse: loopType = "ping-pong-reverse" } fmt.Printf("Animation: %s\n", tag.Name) fmt.Printf(" Frames: %d to %d\n", tag.Lo, tag.Hi) fmt.Printf(" Loop: %s (repeat %d times)\n", loopType, tag.Repeat) // Calculate total animation duration var totalDuration time.Duration for i := tag.Lo; i <= tag.Hi; i++ { totalDuration += sprite.Frames[i].Duration } fmt.Printf(" Total duration: %v\n", totalDuration) } } ``` -------------------------------- ### Read Aseprite File with Full Metadata Access Source: https://context7.com/askeladdk/aseprite/llms.txt Use `aseprite.Read()` to decode a file directly into an `Aseprite` struct. This provides granular access to all sprite data, including individual frames, animation tags, and other metadata. ```APIDOC ## Read Aseprite File with Full Metadata Access ### Description Use `aseprite.Read()` to decode a file directly into an `Aseprite` struct with access to frames, tags, and metadata. ### Method N/A (function-based operation) ### Endpoint N/A (file-based operation) ### Parameters None ### Request Example ```go package main import ( "log" "os" "time" "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("animated_sprite.aseprite") if err != nil { log.Fatal(err) } defer file.Close() sprite, err := aseprite.Read(file) if err != nil { log.Fatal(err) } // Access all frames with their durations log.Printf("Total frames: %d", len(sprite.Frames)) for i, frame := range sprite.Frames { log.Printf("Frame %d: bounds=%v, duration=%v", i, frame.Bounds, frame.Duration) } // Access animation tags for _, tag := range sprite.Tags { log.Printf("Tag '%s': frames %d-%d, loop=%d, repeat=%d", tag.Name, tag.Lo, tag.Hi, tag.LoopDirection, tag.Repeat) } // Access the texture atlas image atlasImage := sprite.Image log.Printf("Atlas size: %v", atlasImage.Bounds()) } ``` ### Response #### Success Response (200) - **sprite** (*aseprite.Aseprite) - A struct containing all decoded Aseprite data. - **sprite.Frames** ([]aseprite.Frame) - A slice of frames, each with bounds and duration. - **sprite.Tags** ([]aseprite.Tag) - A slice of animation tags, defining frame ranges and loop behavior. - **sprite.Image** (image.Image) - The texture atlas image containing all frames. #### Response Example ``` Total frames: 10 Frame 0: bounds={{0 0} {50 50}}, duration=100ms Frame 1: bounds={{50 0} {100 50}}, duration=100ms ... Tag 'walk': frames 0-4, loop=0, repeat=0 Tag 'attack': frames 5-9, loop=1, repeat=0 Atlas size: (0,0)-(100,50) ``` ``` -------------------------------- ### Decode Aseprite File Using Standard Image Package Source: https://context7.com/askeladdk/aseprite/llms.txt Decode an Aseprite file using Go's standard `image.Decode` function. The decoder is automatically registered on package import, allowing you to treat Aseprite files like any other supported image format. ```APIDOC ## Decode Aseprite File Using Standard Image Package ### Description Decode an Aseprite file using Go's standard `image.Decode` function. The decoder is automatically registered on package import. ### Method N/A (uses standard library function) ### Endpoint N/A (file-based operation) ### Parameters None ### Request Example ```go package main import ( "image" "log" "os" _ "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("sprite.aseprite") if err != nil { log.Fatal(err) } defer file.Close() img, format, err := image.Decode(file) if err != nil { log.Fatal(err) } if format != "aseprite" { log.Fatalf("unexpected format: %s", format) } // img is now an image.Image containing all frames arranged in an atlas bounds := img.Bounds() log.Printf("Atlas dimensions: %dx%d", bounds.Dx(), bounds.Dy()) } ``` ### Response #### Success Response (200) - **img** (image.Image) - A standard Go `image.Image` containing all frames arranged in an atlas. - **format** (string) - The format of the image, which will be "aseprite". #### Response Example ``` Atlas dimensions: 100x200 ``` ``` -------------------------------- ### Read Aseprite File with Full Metadata (Go) Source: https://context7.com/askeladdk/aseprite/llms.txt Reads an Aseprite file directly into an `Aseprite` struct using `aseprite.Read()`. This provides full access to all frames, their durations, animation tags, and other metadata. The `Aseprite` struct contains the texture atlas image and all parsed sprite information. ```go package main import ( "log" "os" "time" "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("animated_sprite.aseprite") if err != nil { log.Fatal(err) } defer file.Close() sprite, err := aseprite.Read(file) if err != nil { log.Fatal(err) } // Access all frames with their durations log.Printf("Total frames: %d", len(sprite.Frames)) for i, frame := range sprite.Frames { log.Printf("Frame %d: bounds=%v, duration=%v", i, frame.Bounds, frame.Duration) } // Access animation tags for _, tag := range sprite.Tags { log.Printf("Tag '%s': frames %d-%d, loop=%d, repeat=%d", tag.Name, tag.Lo, tag.Hi, tag.LoopDirection, tag.Repeat) } // Access the texture atlas image atlasImage := sprite.Image log.Printf("Atlas size: %v", atlasImage.Bounds()) } ``` -------------------------------- ### Decode Aseprite File with Go's image.Decode Source: https://context7.com/askeladdk/aseprite/llms.txt Decodes an Aseprite file using the standard Go `image.Decode` function. The aseprite package automatically registers itself upon import. This method returns an `image.Image` representing the texture atlas of all frames and the format string 'aseprite'. ```go package main import ( "image" "log" "os" _ "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("sprite.aseprite") if err != nil { log.Fatal(err) } defer file.Close() img, format, err := image.Decode(file) if err != nil { log.Fatal(err) } if format != "aseprite" { log.Fatalf("unexpected format: %s", format) } // img is now an image.Image containing all frames arranged in an atlas bounds := img.Bounds() log.Printf("Atlas dimensions: %dx%d", bounds.Dx(), bounds.Dy()) } ``` -------------------------------- ### Access Animation Tags and Loop Directions Source: https://context7.com/askeladdk/aseprite/llms.txt Extract animation tags that define frame ranges and loop behavior for different animations within a sprite. This allows for precise control over playback of sprite animations. ```APIDOC ## Access Animation Tags and Loop Directions ### Description Extract animation tags that define frame ranges and loop behavior for different animations within a sprite. ### Method N/A (function-based operation) ### Endpoint N/A (file-based operation) ### Parameters None ### Request Example ```go package main import ( "fmt" "log" "os" "time" "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("character.aseprite") if err != nil { log.Fatal(err) } defer file.Close() sprite, err := aseprite.Read(file) if err != nil { log.Fatal(err) } // Process each animation tag for _, tag := range sprite.Tags { var loopType string switch tag.LoopDirection { case aseprite.Forward: loopType = "forward" case aseprite.Reverse: loopType = "reverse" case aseprite.PingPong: loopType = "ping-pong" case aseprite.PingPongReverse: loopType = "ping-pong-reverse" } fmt.Printf("Animation: %s\n", tag.Name) fmt.Printf(" Frames: %d to %d\n", tag.Lo, tag.Hi) fmt.Printf(" Loop: %s (repeat %d times)\n", loopType, tag.Repeat) // Calculate total animation duration var totalDuration time.Duration for i := tag.Lo; i <= tag.Hi; i++ { totalDuration += sprite.Frames[i].Duration } fmt.Printf(" Total duration: %v\n", totalDuration) } } ``` ### Response #### Success Response (200) - **sprite.Tags** ([]aseprite.Tag) - A slice of animation tags. - **tag.Name** (string) - The name of the animation tag. - **tag.Lo** (int) - The starting frame index of the tag. - **tag.Hi** (int) - The ending frame index of the tag. - **tag.LoopDirection** (aseprite.LoopDirection) - The loop direction enum (Forward, Reverse, PingPong, PingPongReverse). - **tag.Repeat** (int) - The number of times the tag should repeat. #### Response Example ``` Animation: walk Frames: 0 to 4 Loop: forward (repeat 0 times) Total duration: 500ms Animation: attack Frames: 5 to 9 Loop: reverse (repeat 0 times) Total duration: 500ms ``` ``` -------------------------------- ### Decode Aseprite File to Image - Go Source: https://github.com/askeladdk/aseprite/blob/master/README.md Decodes an Aseprite sprite file into a standard Go image.Image. It uses the `image.Decode` function, which requires importing the aseprite package to register its decoder. The output is a generic image and its format, or an error if decoding fails. ```go import ( _ "github.com/askeladdk/aseprite" ) img, imgformat, err := image.Decode("test.aseprite") ``` -------------------------------- ### Access Frame User Data and Layer Metadata in Go Source: https://context7.com/askeladdk/aseprite/llms.txt This Go code snippet demonstrates how to read an Aseprite file and access custom user data attached to layers and frames. It utilizes the 'github.com/askeladdk/aseprite' package for parsing the file. The output includes the count of visible layers with user data and the specific data strings for layers and frame cels. ```go package main import ( "log" "os" "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("annotated_sprite.aseprite") if err != nil { log.Fatal(err) } defer file.Close() sprite, err := aseprite.Read(file) if err != nil { log.Fatal(err) } // Access layer user data log.Printf("Visible layers with user data: %d", len(sprite.LayerData)) for i, data := range sprite.LayerData { if len(data) > 0 { log.Printf("Layer %d user data: %s", i, string(data)) } } // Access frame cel user data for i, frame := range sprite.Frames { if len(frame.Data) > 0 { log.Printf("Frame %d has %d cel(s) with user data", i, len(frame.Data)) for j, celData := range frame.Data { log.Printf(" Cel %d data: %s", j, string(celData)) } } } } ``` -------------------------------- ### Type Cast image.Image to Aseprite Metadata in Go Source: https://context7.com/askeladdk/aseprite/llms.txt This Go code snippet shows how to decode an Aseprite file using the standard 'image' package and then type cast the resulting 'image.Image' to '*aseprite.Aseprite' to access animation-specific metadata. It checks the file format and proceeds to log the number of frames, tags, and slices if the format is 'aseprite'. ```go package main import ( "image" "log" "os" _ "github.com/askeladdk/aseprite" "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("sprite.aseprite") if err != nil { log.Fatal(err) } defer file.Close() img, format, err := image.Decode(file) if err != nil { log.Fatal(err) } // Check format and type cast if format == "aseprite" { sprite, ok := img.(*aseprite.Aseprite) if !ok { log.Fatal("failed to type cast to *aseprite.Aseprite") } // Now access all Aseprite-specific features log.Printf("Successfully loaded sprite with %d frames", len(sprite.Frames)) log.Printf("Animation tags: %d", len(sprite.Tags)) log.Printf("Slices: %d", len(sprite.Slices)) // Use the sprite for rendering or processing for i, frame := range sprite.Frames { log.Printf("Frame %d at %v, duration: %v", i, frame.Bounds, frame.Duration) } } else { log.Printf("Not an Aseprite file, format: %s", format) } } ``` -------------------------------- ### Access Aseprite Frame Data - Go Source: https://github.com/askeladdk/aseprite/blob/master/README.md Accesses detailed frame and metadata from a decoded Aseprite image. After decoding, the image can be type-casted to `aseprite.Aseprite` to iterate through frames and access other extracted information. ```go if imgformat == "aseprite" { sprite := img.(*aseprite.Aseprite) for _, frame := range sprite.Frames { // etc ... } } ``` -------------------------------- ### Extract Frame Images from Aseprite Texture Atlas Source: https://context7.com/askeladdk/aseprite/llms.txt Extracts each frame from an Aseprite texture atlas into individual PNG files. This function requires the 'github.com/askeladdk/aseprite' library and outputs separate image files for each animation frame, logging the bounds and duration. ```go package main import ( "fmt" "image" "image/png" "log" "os" "github.com/askeladdk/aseprite" ) func main() { file, err := os.Open("sprite.aseprite") if err != nil { log.Fatal(err) } defer file.Close() sprite, err := aseprite.Read(file) if err != nil { log.Fatal(err) } // Extract each frame as a separate image for i, frame := range sprite.Frames { // Create a new image for this frame frameImg := image.NewRGBA(frame.Bounds) // Copy pixels from atlas to frame image for y := frame.Bounds.Min.Y; y < frame.Bounds.Max.Y; y++ { for x := frame.Bounds.Min.X; x < frame.Bounds.Max.X; x++ { color := sprite.Image.At(x, y) frameImg.Set(x-frame.Bounds.Min.X, y-frame.Bounds.Min.Y, color) } } // Save frame to file outFile, err := os.Create(fmt.Sprintf("frame_%03d.png", i)) if err != nil { log.Printf("Error creating frame %d: %v", i, err) continue } if err := png.Encode(outFile, frameImg); err != nil { log.Printf("Error encoding frame %d: %v", i, err) } outFile.Close() log.Printf("Extracted frame %d: %v, duration: %v", i, frame.Bounds, frame.Duration) } } ``` -------------------------------- ### Directly Read Aseprite Sprite - Go Source: https://github.com/askeladdk/aseprite/blob/master/README.md Directly decodes an Aseprite sprite file into an `aseprite.Aseprite` struct using the `aseprite.Read` function. This function takes an `io.Reader` as input and returns the decoded sprite object or an error. ```go sprite, err := aseprite.Read(f) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.