使用 php 调整嵌入视频的大小 [英] Resizing embedded videos with php

查看:30
本文介绍了使用 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>

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

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 ?

推荐答案

如果我必须执行类似的任务,我会将 html 转换为 xml 并获取高度/宽度.之后我会调整高度或宽度(取决于你需要什么)保持方面.这样做不会调整实际视频的大小,但会帮助您通过 HTML 调整其大小.

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

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

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

这篇关于使用 php 调整嵌入视频的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆