上传视频片段显示视频拇指图像不起作用? PHP

时间:2013-08-19 13:26:51

标签: php

我创建了一个upload_video.php页面并且遇到了问题。希望一些PHP天才愤怒:可以帮助我一点点,我会非常感激。

更改我的视频页面不会显示视频缩略图。链接到include / generatevideothumb.php

在我的upload_video.php页面中,我已经定义了拇指变量,如下所示

// Thumb size
$th_max_height1 = 150;
$th_max_width1 = 250;
$th_max_width = 55;
$th_max_height = 55;
$thumb_dir="upload/video/thumbs/";
$thumb_dir1="upload/video/thumbs1/";


// Thumb
$thumb_video_name=$video_name;
generatevideothumb($dir,$th_max_width, $th_max_height,$thumb_dir,$thumb_video_name);
generatevideothumb($dir,$th_max_width1, $th_max_height1,$thumb_dir1,$thumb_video_name);

问题在于创建视频缩略图。错误是: 警告:imagecreate()[function.imagecreate]:第25行的html \ include \ generatevideothumb.php中的图像尺寸无效

完整的代码来自下面的generatevideothumb.php

<?php
function generatevideothumb($im_file,$th_max_width, $th_max_height,$thumb_dir,$thumb_video_name)
{
@chmod($im_file,0777);
$image_attribs = getimagesize($im_file);

if($image_attribs[0]>$th_max_width)
{
$ratio = $th_max_width/$image_attribs[0];
$th_width = $image_attribs[0] * $ratio;
$th_height = $image_attribs[1] * $ratio;
}
elseif($image_attribs[1]>$th_max_height)
{
$ratio = $th_max_height/$image_attribs[1];
$th_width = $image_attribs[0] * $ratio;
$th_height = $image_attribs[1] * $ratio;
}
else
{
$th_width = $image_attribs[0];
$th_height = $image_attribs[1];
}
**//This code below is where I get that error saying invalid image dimensions
$im_new = imagecreate($th_width,$th_height); //returns an image identifier representing a black image of size x_size by y_size.
$th_file_name = $thumb_dir.$thumb_video_name;
@chmod($th_file_name,0777);**

if($image_attribs[2]==2)
{
$im_old = imageCreateFromJpeg($im_file);
imagecopyresized($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]);
imagejpeg($im_new,$th_file_name,100);
}
elseif($image_attribs[2]==1)
{
$im_old = imagecreatefromgif($im_file);
imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]);
imagegif($im_new,$th_file_name,100);
}

}
?> 

1 个答案:

答案 0 :(得分:0)

在我看来,您使用的是错误的缩略图尺寸。请回复

<?php
    echo $th_width ."  ".$th_height; //check their values what are you getting

    //before to call following function
    $im_new = imagecreate($th_width,$th_height); 
?>