sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:

Simply put, I need a way to open an image (png, jpg or gif) and export it into SWF. That's it. Just an image that's not right clickable. Yes, I know there are ways to steal it, but I think this is the best idea for now.

I was looking at three mods.

1) SWF::Builder - This looks good and it does talk a little about Bitmaps, but it doesn't show any solid examples of how to use it.

2) SWF::File - Similar to the above module, but looks like there's less documentation for bitmaps.

3) MING - Looks good, but my host doesn't have it and it doesn't look like they'll install it for me. So I'm tough out of luck on this one.

Anyone familiar with opening an image into a SWF? Anyone have a small example of any of the above modules?

Thanks everyone!



"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Image to SWF
by moklevat (Priest) on Feb 23, 2006 at 03:38 UTC
    Your module instincts were correct.

    I've never done anything like this before, but here is a very simple example of putting a jpeg into a swf movie. This is a crude adaptation of code from the docs for SWF::Builder. It works for me under linux and ActiveState on WinXP.
    #!/usr/bin/perl -w use strict; use SWF::Builder; my $movie = SWF::Builder->new ( FrameRate => 15, FrameSize => [0, 0, 400, 400], BackgroundColor => 'ffffff' ); my $jpeg = $movie->new_jpeg('winter.jpg'); $jpeg->place; $movie->save('winter.swf');
      It took me a bit to get the module working. I installed SWF::Builder and it secretely needed Data::TemporaryBag.

      Using your code I get an error now. The error is "Can't place the imported bitmap because it's size is unknown at swf.pl".

      UPDATE Now I get an error that says it cannot get the height and width of the bitmap. I think it couldn't get the file before because I typed in the wrong file path. But now it can't get the dimensions. Is there a way for me to hack around it with image::info h&w params?

      #!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); use lib "/home/everyday/public_html/lib"; use SWF::Builder; my $movie = SWF::Builder->new ( FrameRate => 15, FrameSize => [0, 0, 400, 400], BackgroundColor => 'ffffff' ); my $jpeg = $movie->new_jpeg('spyder_avie.jpg'); $jpeg->place; $movie->save('winter.swf');
      Any idea what this error means? I tried tossing it at google but nothing is coming back.


      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid
        This is really beyond my perlitude, but in looking at the relevant code in Bitmap.pm there seems to be a typo at line 85: $self->{_jepgdata} = $_[0];

        I suspect that it should be $self->{_jpegdata} = $_[0]; instead.

        Does changing this on your installation resolve the error?

        Here is the whole sub:
        sub JPEGData { my $self = shift; my $pos = 2; my $len = length($_[0]); $self->{_jepgdata} = $_[0]; while((my $s=substr($_[0], $pos, 2)) ne "\xff\xc0" and $pos < $len +) { $pos += 2+unpack('n', substr($_[0], $pos+2,2)); } croak "Can't get the width and height of JPEG data" if $pos>=$len; @{$self}{qw/_width _height/} = unpack('nn', substr($_[0], $pos+5,4 +)); undef $self->{_jpegfile}; $self; }
Re: Image to SWF
by zentara (Cardinal) on Feb 23, 2006 at 13:13 UTC
    MING can be tricky to install, but it can be done. Tell your ISP admin to check out Running SWF with Ming if he has trouble.

    In case you want to go with pure Perl, SWF::File has an img2swf.plx and jpeg2swf.plx scripts in it's samples directory. They work, and they are pure perl, so you could use them in your home dir. The img2swf script uses Image Magick to convert formats.