简体   繁体   English

从MS Tag Rest保存标签图像

[英]Save Tag Images from MS Tag Rest

I'm trying to create some Microsoft Tags using the MS Tag Rest Interface (http://tag.ws.suddenelfilio.net/). 我正在尝试使用MS Tag Rest界面(http://tag.ws.suddenelfilio.net/)创建一些Microsoft标签。 I have an API key and was able to create the tag, unfortunately I don't really know how to save it as an image. 我有一个API密钥,并且能够创建标签,但是不幸的是,我并不真正知道如何将其另存为图像。 I have saved the result of the "Generating the barcode" request as an image, and it's about 280k big. 我已将“生成条形码”请求的结果另存为图像,它的大小约为280k。 Unfortunately it doesn't seem to be a valid jped file, imagecreatefromstring() didn't work either. 不幸的是,它似乎不是有效的jped文件,imagecreatefromstring()也不起作用。 imagecreatefromstring returns a imagecreatefromstring返回一个

"Warning: imagecreatefromstring() [function.imagecreatefromstring]: Data is not in a recognized format".

Here's a short snippet of the string I get returned: 这是我返回的字符串的简短片段:

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAdyCA8DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQID

Anyone got this working? 任何人都可以工作吗? Thx 谢谢

在将其传递给imagecreatefromstring ,或者将其保存后再进行解码,看起来是base64编码对其进行解码(使用base64_decode )。

So with the help of Musa I finally figured out how to do this, here's the working code 因此,在Musa的帮助下,我终于找到了解决方法,这是工作代码

Thanks, this was a key part to solving this. 谢谢,这是解决此问题的关键部分。 Here's my now working code: 这是我现在正在工作的代码:

$url = 'http://tag.ws.suddenelfilio.net/mstagrest.svc/GenerateQRcode?at={access-token}&cn=Main&tn=Test&it=jpeg&s=1&ht=true';

// Get page content with curl   
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$pagecontent = curl_exec($ch); 
curl_close($ch);

// Decode it    
$pagecontent = base64_decode($pagecontent);
// Create Image
$im = imagecreatefromstring($pagecontent);
// Save as jpeg
header('Content-Type: image/jpeg');
imagejpeg($im, 'image.jpeg');       

imagedestroy($im);

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

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