图像创建从jpeg() PHP
我正在使用 imagecreatefromjpeg() 函数来合并两张图片。
现在我面临的问题是,当我使用服务器中的图片时,它工作得很好,而当我使用其他网站上的图片时,它就不行了工作。
例如:当我使用这个 PHP 文件 http://coolfbapps.in/test/merger.php with function
imagecreatefrompng('http://coolfbapps.in/test/1.png');
它工作得很好,因为图像位于我自己的服务器上,
放置不在我的服务器上的图像的链接
但是当我更改此函数时,例如,
imagecreatefrompng('http://www.businesseconomics/Test.png');
。它不起作用。 (图像文件不在我的服务器上)
请建议我使用此功能的替代方案或解决方案,因为我想在 Facebook 应用程序中使用此功能。
像 file-get-contents 这样的功能也显示相同的错误。我希望这不是服务器端问题.. allowed_url_fopen 已打开,但是 allow_url_include 已关闭
更新...实际代码。我用它来合并两张图片
$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);
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.
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,
for example.
imagecreatefrompng('http://www.businesseconomics/Test.png');
it doesnt work. (the image file is not on my server)
please suggest me an alternative to this function or a solution as I want to use this with Facebook apps..
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
Update...Actual code. I'm using this to merger two pictures
$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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
cURL
来获取图像数据,而不是使用file_get_content
。这是一个资源:http://php.net/manual/en/book.curl.php
获取 html 的示例(图像也可以):
Instead of using
file_get_content
you can usecURL
to get your image data. Here is a resource:http://php.net/manual/en/book.curl.php
Example with getting html ( images will also work ):
听起来该函数没有 URL 打开功能,或者有,并且您有
allow_url_fopen
在php.ini
中关闭。出于安全原因,您不能使用ini_set()
。您可以将该文件下载到本地服务器,然后打开它。
您也可以使用
copy()
,文档暗示它可以读取 URL。Sounds like the function does not have URL opening capabilities, or it does and you have
allow_url_fopen
off inphp.ini
. You can't useini_set()
for security reasons.You could download the file to your local server, and then open it.
You could probably use
copy()
too, the docs hint that it can read URLs.像这样的事情可能会有所帮助。
已更新::
Something like this might help.
UPDATED::