duanquanhan2333 2010-11-09 10:59
浏览 78
已采纳

使用php调整嵌入视频的大小

Hello i am trying to develop a video gallery
However the problem is that i should limit their dimensions. So if the site owner wants to add a video he should paste the embed code..

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/R6uJGqS-KQY?fs=1&amp;hl=el_GR"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/R6uJGqS-KQY?fs=1&amp;hl=el_GR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>

I decided to go with embed because there are many video providers out there....
So which is the best method to resize it before storing it to the database?
IS there a css only solution?
Also i noticed that video.google uses only and inline css for width height! That would overide any css setting...
So regexp is the only solution ?

  • 写回答

2条回答 默认 最新

  • dongyun8075 2010-11-10 03:41
    关注

    If I had to do a similar task I would convert the html into xml and get the height/width. After that I would resize the height or width (depending on what you need) keeping the aspect. Doing this will not resize the actual video but it'll help you to resize it via HTML.

    <?php
    
    $string = <<<XML
    <?xml version='1.0'?> 
    <object width="480" height="385">
           <param name="movie" value="http://www.youtube.com/v/R6uJGqS-KQY?fs=1&amp;hl=el_GR"> </param>                    
           <param name="allowFullScreen" value="true"></param>
           <param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/v/R6uJGqS-KQY?fs=1&amp;hl=el_GR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"     width="480" height="385"></embed>                
        </object>
    XML;
    $xml = simplexml_load_string($string);                                        
    echo "Original Width/Height:".$xml->attributes()->width."px/".$xml->attributes()->height."px<br>";
    
    $newwidth = 280;
    $newheight = ($xml->attributes()->height / $xml->attributes()->width) * $newwidth;
    
    echo "New Width/Height:".$newwidth."px/".$newheight."px<br>";
    
    echo <<<HTML
        <object width="{$newwidth}" height="${newheight}">
        <param name="movie" value="http://www.youtube.com/v/R6uJGqS-KQY?fs=1&    amp;hl=el_GR"> </param>
            <param name="allowFullScreen" value="true"></param>
            <param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/v/R6uJGqS-KQY?fs=1&amp;hl=el_GR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"     width="${newwidth}" height="${newheight}"></embed>
        </object>
    HTML;
    ?>
    

    I've tested this and you can see it in action at:
    Demo: http://itnews-bg.com/test.php
    Source: http://itnews-bg.com/test.phps

    There may be other better ways but this is what I would do. Hope it helps you :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了