Last active
December 19, 2016 07:46
-
-
Save take-piro/d1a968aaf6bb4f10bffe3e3f016cdd01 to your computer and use it in GitHub Desktop.
swfファイルから画像を抽出するPHPスクリプト(要SWFEditor)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* このスクリプトを動かすには, @yoya 氏の SWFEditor が必要です. | |
* https://pwiki.awm.jp/~yoya/?swfed | |
* | |
* このスクリプト自体どこかで公開されていたコードです. | |
* ざっと検索してみたけど見当たらなかったので,ここに残しておきます | |
* 元記事: http://d.hatena.ne.jp/yoya/20090914/swfimagedump | |
* | |
* How to use: | |
* php GetImgFromSwf.php target.swf | |
* | |
* 実行ファイルとswfファイルを同じディレクトリに置いて実行すると, | |
* そのディレクトリにswfで使用されている画像が抽出される.(タグIDがファイル名になっている) | |
* | |
* 自分の用途としては, | |
* 『flaファイル無いけどこの部分の画像を差し替えたい…でもタグIDが分からない…』 | |
* とりあえず画像を抽出してみて,差し替えたいとこのIDを特定して, | |
* あとはSWFEditorなり,swfmillなり,Pexなりで置換する. | |
*/ | |
if ($argc < 2) { | |
fprintf(STDERR, "Usage: swfimagedump <swf_file>\n"); | |
exit(1); | |
} | |
$swf_filename = $argv[1]; | |
$swfdata = file_get_contents($swf_filename); | |
$obj = new SWFEditor(); | |
if ($obj->input($swfdata) == false) { | |
fprintf(STDERR, "input failed\n"); | |
exit(1); | |
} | |
$tags = $obj->getTagList(); | |
foreach ($tags as $k => $tag) { | |
$tagName = $tag['tagName']; | |
if (strncmp($tagName, 'DefineBitsJPEG', 14) == 0) { | |
$detail = $obj->getTagDetail($k); | |
$imageId = $detail["image_id"]; | |
file_put_contents($imageId.'.jpg', $obj->getJpegData($imageId)); | |
} elseif (strncmp($tagName, 'DefineBitsLossless', 18) == 0) { | |
$detail = $obj->getTagDetail($k); | |
$imageId = $detail["image_id"]; | |
file_put_contents($imageId.'.png', $obj->getPNGData($imageId)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment