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

发布于 2024-09-30 23:53:39 字数 761 浏览 3 评论 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>

我决定使用嵌入,因为那里有很多视频提供商......
那么在将其存储到数据库之前调整其大小的最佳方法是什么?
有没有仅 CSS 的解决方案?
我还注意到 video.google 仅使用内联 css 来表示宽度和高度!这将覆盖任何 css 设置...
那么正则表达式是唯一的解决方案吗?

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&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&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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟凡古楼 2024-10-07 23:53:39

如果我必须做类似的任务,我会将 html 转换为 xml 并获取高度/宽度。
之后,我会调整高度或宽度的大小(取决于您的需要)以保持外观。
这样做不会调整实际视频的大小,但会帮助您通过 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&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&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&hl=el_GR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"     width="${newwidth}" height="${newheight}"></embed>
    </object>
HTML;
?>

我已经对此进行了测试,您可以在以下位置查看它的实际效果:
演示:http://itnews-bg.com/test.php
来源:http://itnews-bg.com/test.phps

可能有其他更好的方法,但这就是我会做的。
希望对你有帮助:)

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&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&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&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 :)

疯到世界奔溃 2024-10-07 23:53:39

当我必须使用 dailymotion 视频的嵌入代码时,这会出现错误:

<object width="480" height="360">
  <param name="movie" value="http://www.dailymotion.com/swf/video/x9rswu?width=&theme=none&foreground=%23F7FFFD&highlight=%23FFC300&background=%23171D1B&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0"></param>
  <param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param>
  <embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/x9rswu?width=&theme=none&foreground=%23F7FFFD&highlight=%23FFC300&background=%23171D1B&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0" width="480" height="360" allowfullscreen="true" allowscriptaccess="always"> </embed>
</object>

That provides error when i have to use embed code of dailymotion video:

<object width="480" height="360">
  <param name="movie" value="http://www.dailymotion.com/swf/video/x9rswu?width=&theme=none&foreground=%23F7FFFD&highlight=%23FFC300&background=%23171D1B&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0"></param>
  <param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param>
  <embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/x9rswu?width=&theme=none&foreground=%23F7FFFD&highlight=%23FFC300&background=%23171D1B&start=&animatedTitle=&iframe=0&additionalInfos=0&autoPlay=0&hideInfos=0" width="480" height="360" allowfullscreen="true" allowscriptaccess="always"> </embed>
</object>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文