psd_sdk 0.2.0
psd_sdk: ^0.2.0 copied to clipboard
A Dart library that directly reads Photoshop PSD files. Supports limited export functionality.
psd_sdk #
A Dart library for reading and manipulating Photoshop PSD files. This library is a Dart port of the original psd_sdk by Molecular Matters.
Features #
Reading Capabilities #
- ✅ Full support for PSD file structure
- ✅ Layer groups and nested layers
- ✅ Smart Objects
- ✅ User and vector masks
- ✅ Transparency masks and additional alpha channels
- ✅ Support for 8-bit, 16-bit, and 32-bit data
- ✅ Grayscale and RGB color modes
- ✅ All Photoshop compression types (RAW, RLE, ZIP, ZIP with prediction)
Export Capabilities #
- ✅ Basic export functionality
- ✅ Layer data extraction
- ✅ Channel data access
- ✅ Mask data retrieval
Installation #
Add the package to your pubspec.yaml
:
dependencies:
psd_sdk: ^0.2.0
Then run:
dart pub get
Usage #
Reading a PSD File #
import 'dart:io';
import 'package:psd_sdk/psd_sdk.dart';
void main() async {
// Load a PSD file
final file = File.fromByteData(File('path/to/your/file.psd').readAsBytesSync());
final document = Document.fromFile(file);
// Access document properties
print('Width: ${document.width}');
print('Height: ${document.height}');
print('Color Mode: ${document.colorMode}');
print('Bits per Channel: ${document.bitsPerChannel}');
// Parse and access layers
final layerMaskSection = document.parseLayerMaskSection(file);
for (final layer in layerMaskSection?.layers ?? []) {
layer.extract(file);
print('Layer: ${layer.name}');
print('Visible: ${layer.visible}');
print('Opacity: ${layer.opacity}');
}
}
Writing a PSD File #
import 'dart:io';
import 'package:psd_sdk/psd_sdk.dart';
void main() async {
// Create a new PSD document
final document = ExportDocument(
800, // width
600, // height
8, // bits per channel
ExportColorMode.rgb // color mode
);
// Add a layer
final layer = document.addLayer(document, 'My Layer');
// Create some sample data
final data = Uint8List(800 * 600);
for (var i = 0; i < data.length; i++) {
data[i] = (i % 255).toInt();
}
// Update layer with data
document.updateLayer(
layer!,
ExportChannel.red,
0, 0, 800, 600, // x, y, width, height
data,
CompressionType.raw
);
// Write to file
final file = File();
document.write(file);
File('output.psd').writeAsBytesSync(file.bytes!);
}
API Reference #
Core Classes #
File
: Base class for handling binary file dataDocument
: Main class for PSD file operations and parsingExportDocument
: Class for creating and exporting PSD filesLayer
: Represents a PSD layer with properties and dataLayerRect
: Interface for layer and mask dimensionsLayerMaskSection
: Container for layer and mask informationChannel
: Represents a channel in a Photoshop layerAlphaChannel
: Represents an alpha channel with color and opacity informationMask
: Base class for layer masksLayerMask
: Represents a layer maskVectorMask
: Represents a vector mask
Utility Classes #
ImageUtil
: Utility class for handling image data operationsSection
: Base class for PSD file sections
Enums #
ColorMode
: Document color modes (Bitmap, Grayscale, RGB, etc.)ChannelType
: Channel data typesLayerType
: Layer typesExportColorMode
: Export color modes (Grayscale, RGB)ExportChannel
: Export channel types (Gray, Red, Green, Blue, Alpha)CompressionType
: Data compression types (Raw, RLE, ZIP, ZIP with prediction)BlendMode
: Layer blend modes (Normal, Multiply, Screen, etc.)AlphaChannelMode
: Alpha channel modes
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
License #
This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.
Acknowledgments #
- Original C++ implementation by Molecular Matters
- Dart port and maintenance by nexo tech
Support #
For support, please open an issue in the GitHub repository.