flash file dimentions (uncompressed files only)
git-svn-id: file:///home/shish/svn/shimmie2/trunk@882 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
babef089bb
commit
2f34a0f153
2 changed files with 68 additions and 8 deletions
|
@ -21,7 +21,8 @@ class FlashFileHandler extends Extension {
|
||||||
send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
|
send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
|
||||||
$image = $this->create_image_from_data("images/$ha/$hash", $event->metadata);
|
$image = $this->create_image_from_data("images/$ha/$hash", $event->metadata);
|
||||||
if(is_null($image)) {
|
if(is_null($image)) {
|
||||||
$event->veto("Flash Handler failed to create image object from data");
|
$event->veto("Flash Handler failed to create image object from data. ".
|
||||||
|
"Note: compressed flash files are currently unsupported");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
send_event(new ImageAdditionEvent($event->user, $image));
|
send_event(new ImageAdditionEvent($event->user, $image));
|
||||||
|
@ -49,10 +50,6 @@ class FlashFileHandler extends Extension {
|
||||||
|
|
||||||
$image = new Image();
|
$image = new Image();
|
||||||
|
|
||||||
// FIXME: need more flash format specs :|
|
|
||||||
$image->width = 0;
|
|
||||||
$image->height = 0;
|
|
||||||
|
|
||||||
$image->filesize = $metadata['size'];
|
$image->filesize = $metadata['size'];
|
||||||
$image->hash = $metadata['hash'];
|
$image->hash = $metadata['hash'];
|
||||||
$image->filename = $metadata['filename'];
|
$image->filename = $metadata['filename'];
|
||||||
|
@ -60,12 +57,70 @@ class FlashFileHandler extends Extension {
|
||||||
$image->tag_array = tag_explode($metadata['tags']);
|
$image->tag_array = tag_explode($metadata['tags']);
|
||||||
$image->source = $metadata['source'];
|
$image->source = $metadata['source'];
|
||||||
|
|
||||||
|
$rect = $this->swf_get_bounds($filename);
|
||||||
|
if(is_null($rect)) {
|
||||||
|
return $null;
|
||||||
|
}
|
||||||
|
$image->width = $rect[1];
|
||||||
|
$image->height = $rect[3];
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function str_to_binarray($string) {
|
||||||
|
$binary = array();
|
||||||
|
for($j=0; $j<strlen($string); $j++) {
|
||||||
|
$c = ord($string[$j]);
|
||||||
|
for($i=7; $i>=0; $i--) {
|
||||||
|
$binary[] = ($c >> $i) & 0x01;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $binary;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function binarray_to_int($binarray, $start=0, $length=32) {
|
||||||
|
$int = 0;
|
||||||
|
for($i=$start; $i<$start + $length; $i++) {
|
||||||
|
$int = $int << 1;
|
||||||
|
$int = $int + ($binarray[$i] == "1" ? 1 : 0);
|
||||||
|
}
|
||||||
|
return $int;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function swf_get_bounds($filename) {
|
||||||
|
$fp = fopen($filename, "r");
|
||||||
|
$head = fread($fp, 3);
|
||||||
|
$version = fread($fp, 1);
|
||||||
|
$length = fread($fp, 4);
|
||||||
|
|
||||||
|
if($head == "FWS") {
|
||||||
|
$data = fread($fp, 16);
|
||||||
|
}
|
||||||
|
else if($head == "CWS") {
|
||||||
|
// inflate data
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$bounds = array();
|
||||||
|
$rect_bin = $this->str_to_binarray($data);
|
||||||
|
$nbits = $this->binarray_to_int($rect_bin, 0, 5);
|
||||||
|
$bounds[] = $this->binarray_to_int($rect_bin, 5 + 0 * $nbits, $nbits) / 20;
|
||||||
|
$bounds[] = $this->binarray_to_int($rect_bin, 5 + 1 * $nbits, $nbits) / 20;
|
||||||
|
$bounds[] = $this->binarray_to_int($rect_bin, 5 + 2 * $nbits, $nbits) / 20;
|
||||||
|
$bounds[] = $this->binarray_to_int($rect_bin, 5 + 3 * $nbits, $nbits) / 20;
|
||||||
|
|
||||||
|
return $bounds;
|
||||||
|
}
|
||||||
|
|
||||||
private function check_contents($file) {
|
private function check_contents($file) {
|
||||||
// FIXME: flash magic header?
|
if(!file_exists($file)) return false;
|
||||||
return (file_exists($file));
|
|
||||||
|
$fp = fopen($file, "r");
|
||||||
|
$head = fread($fp, 3);
|
||||||
|
fclose($fp);
|
||||||
|
if(!array_contains(array("CWS", "FWS"), $head)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_event_listener(new FlashFileHandler());
|
add_event_listener(new FlashFileHandler());
|
||||||
|
|
|
@ -6,11 +6,16 @@ class FlashFileHandlerTheme extends Themelet {
|
||||||
// FIXME: object and embed have "height" and "width"
|
// FIXME: object and embed have "height" and "width"
|
||||||
$html = "
|
$html = "
|
||||||
<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
|
<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
|
||||||
codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'>
|
codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'
|
||||||
|
height='{$image->height}'
|
||||||
|
width='{$image->width}'
|
||||||
|
>
|
||||||
<param name='movie' value='$ilink'/>
|
<param name='movie' value='$ilink'/>
|
||||||
<param name='quality' value='high' />
|
<param name='quality' value='high' />
|
||||||
<embed src='$ilink' quality='high'
|
<embed src='$ilink' quality='high'
|
||||||
pluginspage='http://www.macromedia.com/go/getflashplayer'
|
pluginspage='http://www.macromedia.com/go/getflashplayer'
|
||||||
|
height='{$image->height}'
|
||||||
|
width='{$image->width}'
|
||||||
type='application/x-shockwave-flash'></embed>
|
type='application/x-shockwave-flash'></embed>
|
||||||
</object>";
|
</object>";
|
||||||
$page->add_block(new Block("Image", $html, "main", 0));
|
$page->add_block(new Block("Image", $html, "main", 0));
|
||||||
|
|
Reference in a new issue