SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Know the .swf dimensions

    Hi people.

    Exist some way to know the dimension (width & height) of a .swf file? like I can see with a .jpg or .gif file with the getimagesize() function?

    From now, thanks for any help.

  2. #2
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    getimagesize() supports swf format

  3. #3
    .* draziW tnioPetiS *. bronze trophy
    Join Date
    Jun 2004
    Location
    "Then I figure the most good good guy will win."
    Posts
    1,666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From what I have read, it will also depend on the swf file:

    Note that the canvas of a Flash movie can not be empty for getimagesize() to read the dimensions of an SWF. Not sure if this is a bug, a feature or just a limitation of the SWF format.

    Flash version does not seem to matter. Also tested with Flash 8 beta.
    Additionally, FWIK, getimagesize() will not return dimensions of your swf if Apache zlib is a compiled as a shared module:

    I ran into this problem recently with the servers at my work... Kinda frustrating to get a FALSE return via getimagesize("foo.swf").

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mhulse View Post
    From what I have read, it will also depend on the swf file:



    Additionally, FWIK, getimagesize() will not return dimensions of your swf if Apache zlib is a compiled as a shared module:



    I ran into this problem recently with the servers at my work... Kinda frustrating to get a FALSE return via getimagesize("foo.swf").
    And what about the solution? Did you find any solution for this purpose getting dimensions of the swf files??

    Would you please share it if you found the solution other than getimagesize()?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    .* draziW tnioPetiS *. bronze trophy
    Join Date
    Jun 2004
    Location
    "Then I figure the most good good guy will win."
    Posts
    1,666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rajug.

    First, some background:

    I was in the process of creating a few plugins for a CMS we use at work. These plugins needed to get the image size of the passed-in object (swf, jpg, gif...)

    Long story short, I ended-up appending a query string on the end of the file name that then passed the width/height to the plugin, like so:

    Code HTML4Strict:
    /path/to/my.swf?w=100&h=300

    Kinda hackish, but it works.

    The other option I included in my plugin was for it to get the extension of the file, and based on that, I was able to allow folks to do conditional things... for example, if an SWF, then "do something." This approach, on top of the query string option, allowed me to solve the problem.

    Of course, if getimagesize() worked, then no need to hack-it-up.

    Most servers I have used allow getimagesize of swf files... I was kinda irked when I realized my work server was not setup optimally.

    Anyway... Longer story short... I ended-up finding a solution that I have yet to test... Not sure, but I think it might work well for both problematic "caveats" I mention in my first post... Though, the person I am quoting below is mostly referring to SWC files, and not SWF files... I have never messed around with SWC files, so not sure if the same rules apply when it comes to the SWF file format:

    The below solution works if the flash file hasnt got an empty frame, basically. A lot of people make flash files without establishing frame dimensions, though. half our flashes work and half don't. Also, you have to figure out how to pump the string back in to getimagesize as a file buffer, so it's a huge pain. Alternately, you can spit out about 1000bytes and look for ### ### or better, ###x####.


    I ran into the same problem when Flash 6 came out, so I tried to fix the problem with PHP code. The SWC format is a regular SWF file, but with a portion of the file compressed with zlib. Unfortunately the width and height of the SWC file is located inside the compressed portion.

    SWF:
    • [HEADER - 3 bytes] 'FWS'
    • [VERSION - 1 byte] In which version was this file created
    • [SIZE - 4 bytes] size of file
    • [TAGS] All tags


    SWC:
    • [HEADER - 3 bytes] 'CWS'
    • [VERSION - 1 byte] In which version was this file created
    • [SIZE - 4 bytes] size of uncompressed file
    • [ZLIBSTREAM] Zlib compressed stream of all tags


    To decompress the file you need to copy the first 8 bytes of the SWC file to a buffer and change to first byte of the buffer to 'C'. Then you need to decompress the remaining bytes of the SWC file and append it to the buffer.

    The following PHP function uses this method to decompress the file:

    PHP Code:
    function phpAds_SWFDecompress($buffer) {
        if (
    function_exists('gzuncompress') && substr($buffer03) == swf_tag_compressed && ord(substr($buffer31)) >= 6) {
            
    $output  'F';
            
    $output .= substr ($buffer17);
            
    $output .= gzuncompress (substr ($buffer8));
            return (
    $output);
        } else { return (
    $buffer); }

    If you are only interested in retrieving the dimensions of the SWC file it can be even easier. Just strip the first 8 bytes of the SWC file and decompress the remaining bytes. The tags for the width and height should be first two tags inside the decompressed stream.
    Not sure who the original quote is by... but I plan on testing this possible solution with my plugins very soon.

    I also ran into problems with .mov's.... getimagesize() will not work on .mov files... that is where the query string also came in handy. Hmmm, maybe the above code will work for that too....

    Either way, I plan on testing this soon. Let me know if that helps.

    Cheers,
    Micky

  6. #6
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's the solution we use as well. Define params to the swf call. Works fine

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rajug.
    First, some background:
    I was in the process of creating a few plugins for a CMS we use at work. These plugins needed to get the image size of the passed-in object (swf, jpg, gif...)
    Long story short, I ended-up appending a query string on the end of the file name that then passed the width/height to the plugin, like so:
    HTML4Strict Code:
    /path/to/my.swf?w=100&h=300
    Kinda hackish, but it works.
    Ummmm Thank you very much mhulse. I got now. Thanx for sharing ideas.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •