添加图像层失败(GD)PHP [英] Adding of Image Layer Fails (GD) PHP

查看:77
本文介绍了添加图像层失败(GD)PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Apache上安装了GD Library,看来下面的脚本不起作用. 我正在尝试在youtube视频缩略图(http://img.youtube.com/vi/VIDEOID/default.jpg)上添加"play.png"层

I've installed the GD Library on my Apache just now, and it seems that my script below doesn't work. I'm trying to add a layer "play.png" to a youtube video thumbnail (http://img.youtube.com/vi/VIDEOID/default.jpg)

我尝试了许多不同的videoID,但是图像无法加载.出现一条消息,指出该图形包含错误,因此无法打开.

I've tried it with many different videoID's but the image doesn't load. There is a message that the graphic couldn't be opened because it contains errors.

我正在使用postimage.php?v = 7yV_JtFnIwo打开文件

I'm opening the file with postimage.php?v=7yV_JtFnIwo

http://img.youtube.com/vi/7yV_JtFnIwo/default.jpg 也能正确打开...

http://img.youtube.com/vi/7yV_JtFnIwo/default.jpg opens correctly too...

有人知道问题可能在哪里吗?

Does anyone know where the issue could be?

提前谢谢!

<?php

  // The header line informs the server of what to send the output
  // as. In this case, the server will see the output as a .png
  // image and send it as such

  header ("Content-type: image/png"); 


  // Defining the background image. Optionally, a .jpg image could 
  // could be used using imagecreatefromjpeg, but I personally 
  // prefer working with png

  $background = imagecreatefromjpeg("http://img.youtube.com/vi/".$_GET['v']."/default.jpg"); 


  // Defining the overlay image to be added or combined.

  $insert = imagecreatefrompng("play.png"); 


  // Select the first pixel of the overlay image (at 0,0) and use
  // it's color to define the transparent color

  imagecolortransparent($insert,imagecolorat($insert,0,0));


  // Get overlay image width and hight for later use

  $insert_x = imagesx($insert); 
  $insert_y = imagesy($insert); 


  // Combine the images into a single output image. Some people
  // prefer to use the imagecopy() function, but more often than 
  // not, it sometimes does not work. (could be a bug)

  imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100); 


  // Output the results as a png image, to be sent to viewer's
  // browser. The results can be displayed within an HTML document
  // as an image tag or background image for the document, tables,
  // or anywhere an image URL may be acceptable.

  imagepng($background,"",100); 

?>

推荐答案

请勿使用?>关闭脚本(避免使用空格或新闻行),而应使用NULL代替"".

Do not close (avoid whitespaces or newslines) your script with ?> and use NULL instead "".

imagepng($background, NULL); 

然后,在imagepng中,质量参数在0到9之间,如 http ://it.php.net/manual/en/function.imagepng.php .

Then, in imagepng the quality parameter is between 0 and 9, as in http://it.php.net/manual/en/function.imagepng.php.

这篇关于添加图像层失败(GD)PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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