PHPackages                             arakne/swf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. arakne/swf

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

arakne/swf
==========

SWF parsing and extraction library

v0.5.3(4mo ago)3341721LGPL-3.0-or-laterPHPCI passing

Since Jun 5Pushed 4mo ago4 watchersCompare

[ Source](https://github.com/Arakne/ArakneSwf)[ Packagist](https://packagist.org/packages/arakne/swf)[ RSS](/packages/arakne-swf/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (6)Versions (12)Used By (1)

Arakne SWF - Parse and extract SWF files in PHP
===============================================

[](#arakne-swf---parse-and-extract-swf-files-in-php)

[![Build](https://github.com/Arakne/ArakneSwf/actions/workflows/build.yml/badge.svg)](https://github.com/Arakne/ArakneSwf/actions/workflows/build.yml)[![Packagist](https://camo.githubusercontent.com/2a58894aae9b834f73a4dce157a788188465fd248ee119a2b8dfceee165f529a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6172616b6e652f737766)](https://packagist.org/packages/arakne/swf)[![codecov](https://camo.githubusercontent.com/04e83a480d269f59c03633e74cedbc13255a4e1ccffa6d0b497455c596fe5a9a/68747470733a2f2f636f6465636f762e696f2f6769746875622f4172616b6e652f4172616b6e655377662f67726170682f62616467652e7376673f746f6b656e3d7672656c536466576b70)](https://codecov.io/github/Arakne/ArakneSwf)[![License](https://camo.githubusercontent.com/e5158ec2e997e0565800b3ec8fe1cc065243b0a739ebda028d85f82706a85756/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4172616b6e652f4172616b6e65537766)](./COPYING.LESSER)

Library to parse SWF tags and extract resources like sprites, images, etc. in pure PHP, without any external dependencies. Its goal is to simplify processing of multiple SWF files using a script file.

It renders shapes and sprites in SVG format, and can export images in JPEG or PNG format. It also implements a simple AVM interpreter to extract ActionScript 2 variables.

Use a CLI application
---------------------

[](#use-a-cli-application)

This project can be used as a simple CLI application, if you simply want to extract resources from a SWF file. You can use the `bin/swf-extract` command to do so.

### Installation &amp; show help

[](#installation--show-help)

PHP 8.4 or higher is required. Composer is not required, but it's recommended if you want to use PHP scripts.

It may also require some PHP extensions, depending on the features you want to use:

- `gd` for image processing
- `json` to export variables in JSON format
- `xml` for sprite export (performed in SVG format)
- `Imagick` to convert SVG to PNG or JPEG format

Note

On some systems, the `Imagick` extension does not support well the SVG format, so the conversion may result in a weird image. In this case, try to install `rsvg-convert` command (package `librsvg2-bin` on Debian/Ubuntu, `librsvg2-tools` on Fedora) or `inkscape`. Inkscape is slower than rsvg, but may produce better results.

```
git clone https://github.com/Arakne/ArakneSwf
cd ArakneSwf
bin/swf-extract --help
```

### Usage

[](#usage)

Here some examples of how to use the CLI application. To get the full list of options, run `bin/swf-extract --help`.

```
# Extract the root SWF frames. Will create files `export/my_anim/timeline_[frame].svg` for each frame.
bin/swf-extract --timeline my_anim.swf export

# Extract character exported with name "label" on each SWF files
# Will create files `export/[swf_file_basename]/label_[frame].svg` for each frame.
bin/swf-extract -e label sprites/*.swf export

# Extract all exported symbols from each SWF file
bin/swf-extract --all-exported sprites/*.swf export

# Extract all sprites from foo.swf, using a custom filename format
bin/swf-extract --all-sprites foo.swf --output-filename '{name}.{ext}' foo.swf export

# Same as above, but export as PNG with maximum size of 128x128 pixels
bin/swf-extract --all-sprites foo.swf --frame-format png@128 --output-filename '{name}.{ext}' foo.swf export

# Try to resolve variable defined in ActionScript 2 and export them in JSON format
bin/swf-extract --variables swf/*.swf export
```

Use as a library
----------------

[](#use-as-a-library)

To perform more complex operations, you can use the library as a PHP library.

### Installation &amp; basic usage

[](#installation--basic-usage)

First you need to install the library using Composer:

```
composer require arakne/swf
```

Then you can use the library in your PHP scripts:

```
