imagecreatefromjpeg()php [英] imagecreatefromjpeg() php
问题描述
我正在使用imagecreatefromjpeg()函数合并两张图片..
I'm using imagecreatefromjpeg() function to merge two pictures..
现在我遇到的问题是当我使用服务器上的图片时,它工作得很好,当我使用来自其他网站的图片时,它不起作用。
now the problem which I'm facing is that when I use the pictures from my server, it works perfectly and when I use pictures from some other website, it doesn't work.
例如:当我使用这个PHP文件时 http://coolfbapps.in/test/merger.php 功能
For example: when I use this PHP file http://coolfbapps.in/test/merger.php with function
imagecreatefrompng('http://coolfbapps.in/test/1.png');
由于图像位于我自己的服务器上,因此效果非常好
It works perfectly fine as the image is at my own server
但是当我改变这个功能时,我把一个不在我服务器上的图像链接,
but when I alter this function n put the link of an image which is not on my server,
。
imagecreatefrompng('http://www.businesseconomics/Test.png');
它不起作用。 (图像文件不在我的服务器上)
it doesnt work. (the image file is not on my server)
请建议我替代此功能或解决方案,因为我想在Facebook应用中使用它..
please suggest me an alternative to this function or a solution as I want to use this with Facebook apps..
像file-get-contents这样的函数也显示相同的错误。我希望它不是服务器端问题..
allow_url_fopen已开启但
allow_url_include已关闭
Functions like file-get-contents are also showing the same error. I hope its not server end problem.. allow_url_fopen is on but allow_url_include is off
更新...实际代码。我用它来合并两张照片
$dest = imagecreatefrompng('http://coolfbapps.in/test/1.png');
$src = imagejpeg('http://img.allvoices.com/thumbs/image/111/111/75152279-pic.jpg');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
推荐答案
而不是使用 file_get_content
您可以使用 cURL
来获取图像数据。这是一个资源:
http://php.net/manual/en/ book.curl.php
Instead of using file_get_content
you can use cURL
to get your image data. Here is a resource:
http://php.net/manual/en/book.curl.php
获取html示例(图片也可以):
Example with getting html ( images will also work ):
<?php
$ch = curl_init("http://img.allvoices.com/thumbs/image/111/111/75152279-pic.jpg");
$fp = fopen("example_homepage.jpg", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$img = imagecreatefromjpeg("example_homepage.jpg");
?>
这篇关于imagecreatefromjpeg()php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!