简体   繁体   English

Facebook图形获取个人资料图片图片类型

[英]Facebook graph get profile picture image type

I am trying to duplicate and work with images from Facebook profiles. 我正在尝试复制和使用Facebook个人资料中的图像。 I can get the images just fine. 我可以得到很好的图像。 The majority of them are 'jpgs' however, some of them are 'pngs' and even a few are 'gifs'. 其中大多数是“ jpg”,但其中一些是“ png”,甚至有一些是“ gif”。 There may be others that I don't know about. 可能还有其他我不知道的地方。

My issue. 我的问题。 I need to find out what type of image they are before I work with them. 在与他们合作之前,我需要先弄清楚它们是什么类型的图像。

The below code works to get the image and with json I get the url... but the last line of code will not work unless I have the right image type . 下面的代码可以获取图像,而使用json可以获取url ..., 但是除非我具有正确的图像类型,否则最后一行代码将不起作用

$json = file_get_contents("http://graph.facebook.com/$user[id]/picture?width=512&height=512&redirect=false");

$decoded = json_decode($json,true);
$url = $decoded['data']['url'];



/// This line will only work if the image is a jpeg or it throws an error. 
$source= imagecreatefromjpeg("$url");

Thank you for your help. 谢谢您的帮助。

Grabbed from Create Image From Url Any File Type 从URL从任何文件类型创建图像中获取

 $jpeg_image = imagecreatefromfile( 'photo.jpeg' ); $gif_image = imagecreatefromfile( 'clipart.gif' ); $png_image = imagecreatefromfile( 'transparent_checkerboard.PnG' ); $another_jpeg = imagecreatefromfile( 'picture.JPG' ); // This requires you to remove or rewrite file_exists check: $jpeg_image = imagecreatefromfile( 'http://example.net/photo.jpeg' ); // SEE BELOW HO TO DO IT WHEN http:// ARGS IS NEEDED: $jpeg_image = imagecreatefromfile( 'http://example.net/photo.jpeg?foo=hello&bar=world' ); function imagecreatefromfile( $filename ) { if (!file_exists($filename)) { throw new InvalidArgumentException('File "'.$filename.'" not found.'); } switch ( strtolower( pathinfo( $filename, PATHINFO_EXTENSION ))) { case 'jpeg': case 'jpg': return imagecreatefromjpeg($filename); break; case 'png': return imagecreatefrompng($filename); break; case 'gif': return imagecreatefromgif($filename); break; default: throw new InvalidArgumentException('File "'.$filename.'" is not valid jpg, png or gif image.'); break; } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM