Imagecreatefromjpeg () php

I am using the imagecreatefromjpeg () function to merge two images.

Now the problem that I am facing is that when I use photos from my server, it works fine, and when I use images from another site, it does not 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 great as the image is on my own server

but when I change this function, put a link to an image that is not on my server,

eg.

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

he does not work. (image file is missing on my server)

offer me an alternative to this feature or a solution that I want to use in Facebook applications.

Functions such as file-get-contents also show the same error. I hope this is not a server problem. allow_url_fopen is on but allow_url_include is off

Refresh ... Actual code. I use this to merge two images

  $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
source share
3 answers

Instead of using file_get_content you can use cURL to get your image data. Here is the resource: http://php.net/manual/en/book.curl.php

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"); ?> 
+1
source

It looks like the function does not have the ability to open a URL, or it is, and you allow_url_fopen disabled in php.ini . You cannot use ini_set() for security reasons.

You can upload the file to the local server, and then open it.

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

Perhaps you could use copy() , the docs suggest that it can read the urls.

0
source

Something like this might help.

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

UPDATED ::

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

Source: https://habr.com/ru/post/1347057/


All Articles