<?php

if ($argc < 4) {
    fprintf(STDERR, "Usage: swfreplacejpegdata <swf_file> <image_id> <jpeg_file> [alpha_file]\n");
    exit(1);
}

if ($argc > 3) {
    $swf_filename = $argv[1];
    $image_id = $argv[2];
    $jpeg_filename = $argv[3];
    if ($argc > 4) {
	$alpha_filename = $argv[4];
    }
}

$swfdata = file_get_contents($swf_filename);
$jpegdata = file_get_contents($jpeg_filename);

if (! empty($alpha_filename)) {
    $alphadata = file_get_contents($alpha_filename);
}

$obj = new SWFEditor();
$obj->input($swfdata);
if (empty($alphadata)) {
    $obj->replaceJpegData($image_id, $jpegdata);
} else {
    $obj->replaceJpegData($image_id, $jpegdata, $alphadata);
}

echo $obj->output();
