Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
imagecreatefromjpeg()php_Php_Image_Image.createimage - Fatal编程技术网

imagecreatefromjpeg()php

imagecreatefromjpeg()php,php,image,image.createimage,Php,Image,Image.createimage,我正在使用imagecreatefromjpeg()函数合并两张图片 现在我面临的问题是,当我使用服务器上的图片时,它工作得很好,而当我使用其他网站上的图片时,它不工作 例如:当我将这个PHP文件与函数一起使用时 imagecreatefrompng('http://coolfbapps.in/test/1.png'); 它工作得非常好,因为图像在我自己的服务器上 但是当我改变这个函数时,我会把一个不在我服务器上的图像链接 比如说 imagecreatefrompng('http://w

我正在使用imagecreatefromjpeg()函数合并两张图片

现在我面临的问题是,当我使用服务器上的图片时,它工作得很好,而当我使用其他网站上的图片时,它不工作

例如:当我将这个PHP文件与函数一起使用时

 imagecreatefrompng('http://coolfbapps.in/test/1.png');
它工作得非常好,因为图像在我自己的服务器上

但是当我改变这个函数时,我会把一个不在我服务器上的图像链接

比如说

  imagecreatefrompng('http://www.businesseconomics/Test.png');
它不起作用。(映像文件不在我的服务器上)

请向我推荐此功能的替代方案或解决方案,因为我想在Facebook应用程序中使用此功能

像file get contents这样的函数也显示了相同的错误。我希望这不是服务器端问题。。 allow\u url\u fopen已打开,但 “允许url\u包含”处于禁用状态

更新…实际代码。我用这个来合并两张图片

 $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);

听起来这个函数没有URL打开功能,或者它有,并且您在
php.ini
中关闭了它。出于安全原因,不能使用
ini\u set()

您可以将文件下载到本地服务器,然后打开它

file_put_contents('image.jpg',
                  file_get_contents('http://www.businesseconomics/Test.png')
                 );

您也可以使用,文档提示它可以读取URL。

类似的内容可能会有所帮助

$imagestr = file_get_contents('http://www.businesseconomics/Test.png');

$image = imagecreatefromstring($imagestr);

imagecreatefrompng($image);
已更新

$imagestr = file_get_contents('http://www.gravatar.com/avatar/95111e2f99bb4b277764c76ad9ad3569?s=32&d=identicon&r=PG');

$image = imagecreatefromstring($imagestr);

header('Content-type: image/jpeg');

imagejpeg($image);

您可以使用
cURL
获取图像数据,而不是使用
file\u获取内容。以下是一个资源:

获取html的示例(图像也适用):



allow\u url\u open在php中处于启用状态。如何添加url打开功能?你能帮我一下吗?显示了同样的错误---警告:file\u get\u contents()[函数.file get contents]:无法打开流:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应。@Anurag听起来需要包含协议。与浏览器不同,PHP不会采用浏览器。@alex。。我在这里有点困惑。。我应该如何包含协议?删除图像/jpeg头并仅输出错误。。它到底说了什么?让我指出
http://www.businesseconomics/
可能不是有效的URL。这可能有多个错误。我建议先用
文件获取内容()
获取图像,然后再进行处理,这样你就可以分辨出哪里出了问题。@deceze这只是一个例子。。即使使用正确的url@Anurag你的代码和我的一样好。我认为服务器上出现了一些错误或某些配置错误。文件获取内容也显示了相同的错误。警告:文件获取内容(XXXXX)[function.file get contents]:无法打开流:连接尝试失败,因为连接方在一段时间后没有正确响应,或建立的连接失败,因为连接的主机无法响应。第4行的D:\inetpub\vhosts\coolfbapps.in\httpdocs\test\merge.php中出现致命错误:第4行的D:\inetpub\vhosts\coolfbapps.in\httpdocs\test\merge.php中超过了30秒的最大执行时间……我希望不是服务器problem@Anurag那么,您可以尝试在localserver上使用映像来实现吗,即
http://localhost/img.jpg
先生,即使文件在我自己的服务器上,我也可以使用此功能。。问题只发生在其他服务器上。。是的,本地服务器也可以正常工作。@Anurag我想你应该把这个url指向一些小图片
http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif
现在,让我们看看发生了什么。@Anurag,上面更新的代码对我来说似乎非常合适。但我的主要目标是合并两张图片。。不只是去拿。。imagecreatefromjpeg()不起作用。这是正确的方向。你只需要把剩下的写下来。您需要将本地文件传递到imagecreatefromjpeg(“example_homepage.jpg”),而不是url。
<?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");
?>