|
1 | | -A Swift wrapper for libgd, allowing for basic graphic rendering on server-side Swift where Core Graphics is not available. |
2 | | -Min Swift version is `6.2.0`. |
| 1 | +SwiftLibgd is a Swift wrapper for libgd, providing server-side image manipulation where Core Graphics isn’t available. It allows you to: |
| 2 | +- Load and save PNG/JPEG images. |
| 3 | +- Create, resize, and crop images. |
| 4 | +- Draw lines, shapes (ellipses, rectangles), and images. |
| 5 | +- Read and write individual pixels. |
| 6 | +- Flood fill colors. |
| 7 | +- Flip images horizontally or vertically. |
| 8 | +- Apply basic effects: pixelate, blur, colorize, desaturate. |
| 9 | + |
| 10 | +SwiftLibgd handles GD resources automatically, freeing memory when images are destroyed. |
| 11 | + |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +1. Install the GD library on your system: |
| 16 | +- macOS: Install Homebrew, then run: |
| 17 | +``` |
| 18 | +brew install gd |
| 19 | +``` |
| 20 | +- Linux: Run as root: |
| 21 | +``` |
| 22 | +apt-get install libgd-dev |
| 23 | +``` |
| 24 | + |
| 25 | +2. Add SwiftLibgd to your `Package.swift`: |
| 26 | +``` |
| 27 | +.package(url: "https://github.com/brillcp/swiftlibgd.git", from: "0.1.2") |
| 28 | +``` |
| 29 | + |
| 30 | +3. Include SwiftLibgd in your target dependencies. |
| 31 | +SwiftLibgd has a single Swift dependency: Cgd, which wraps the underlying GD library. |
| 32 | + |
| 33 | +## Classes |
| 34 | + |
| 35 | +SwiftLibgd provides five classes for basic image operations: |
| 36 | +- Image – responsible for loading, saving, and manipulating image data |
| 37 | +- Point – stores x and y coordinates as integers |
| 38 | +- Size – stores width and height as integers |
| 39 | +- Rectangle – combines Point and Size into one value |
| 40 | +- Color – provides red, green, blue, and alpha components as Doubles from 0 to 1, and includes some built-in colors to get you started |
| 41 | + |
| 42 | +These are implemented as classes rather than structs because only classes have deinitializers, which are required to release GD’s memory when an image is destroyed. |
0 commit comments