9

imagecreatefromjpeg() 関数を使用して 2 つの画像を結合しています。

今私が直面している問題は、サーバーの写真を使用すると完全に機能し、他のウェブサイトの写真を使用すると機能しないことです。

例: この PHP ファイルhttp://coolfbapps.in/test/merger.phpを関数で使用する場合

 imagecreatefrompng('http://coolfbapps.in/test/1.png');

画像は自分のサーバーにあるので、問題なく動作します

しかし、この関数を変更すると、サーバーにない画像のリンクを配置し、

例えば。

  imagecreatefrompng('http://www.businesseconomics/Test.png');

それは動作しません。(画像ファイルは私のサーバーにはありません)

Facebookアプリでこれを使用したいので、この機能の代替または解決策を提案してください..

file-get-contents などの関数でも同じエラーが表示されます。サーバー側の問題ではないことを願っています..allow_url_fopenはオンですが、allow_url_includeはオフです

更新...実際のコード。これを使用して2つの写真を結合しています

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

3 に答える 3

2

を使用する代わりに、 をfile_get_content使用cURLして画像データを取得できます。ここにリソースがあります: http://php.net/manual/en/book.curl.php

html を取得する例 (画像も機能します):

<?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");
?>
于 2011-04-08T05:33:41.893 に答える
1

このようなものが役立つかもしれません。

$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);
于 2011-04-07T08:32:31.283 に答える
1

この関数には URL を開く機能がないか、または機能していてallow_url_fopenphp.ini. ini_set()セキュリティ上の理由から使用できません。

ファイルをローカル サーバーにダウンロードしてから開くことができます。

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

おそらく使用することcopy()もできます。ドキュメントは、URLを読み取ることができることを示唆しています。

于 2011-04-07T08:12:46.773 に答える