如何使用PHP从json响应中保存图像

时间:2014-07-06 08:04:16

标签: php html css json image

好的,所以我使用了一个API来获取某些内容的图像,而且该图像不是一个URL的格式?所以如何将其保存到图像文件(.jpeg)

"screenshot": {
"data": "_9j_4AAQSkZJRgABAQAAAQABAAD_2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj_2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj_wAARCADwAUADASIAAhEBAxEB_8QAHAABAAIDAQEBAAAAAAAAAAAAAAMFAQQGAgcI_8QAOxAAAQMCAgcFBwQBAwUAAAAAAAECAwQRBRIGExQhMVFSQVSRk9EHIjJhcYHSFaGi8EIXI-EzgrHB8f_EABoBAQADAQEBAAAAAAAAAAAAAAACBAUDAQb_xAAtEQEAAQMCBAUDBAMAAAAAAAAAAQIDEQQhEjFRUhNBYXGBBTLBIpGx0aLh8f_aAAwDAQACEQMRAD8A_VIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADTrqBlYv-5LM1MisyseqNW6ot1Tmlt31UxSUT6epkkWqnkY5FtE9Uytut9304AbtwVE-CtlrJZ0q6iJZFuqROy-KpvUnwzDVopJZH1U9Q-TtlVFsl1WyeIFgCnlwVyvkdFiFZEr357NfuT3s1kTgh6w7Cp6Z8Ek-I1Uz2IuZqu9x10twXxAsKqqp6VqOqp4oWqtkWR6NRd1-35Iq_Y9wzRzxpJBIySNVVEcxyOS6LZd6fO6FbpDhkuKU0UUMzYlY5yqrkct7sc3sVOZs4RSPoaBkEj0kcj3uzJf_ACeru1VXtA5Ks9puDUlZPTSU9er4ZHRuVsbbKrVVFt73yIf9VcD7tiHlt_I4mr0c0jg0gxOpp8GlnimlmRMytyua5yqi8b8lPVVgmPysiSPRZI5Gua90iI3Mrkfm3LfgvA-njQ6DE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5NG0v6WlW2jmSZr1rp1RqouTsXhuU3gP_9k=",
  "height": 240,
  "mime_type": "image/jpeg",
  "width": 320
 }
}

先谢谢你,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用file_put_contents function.simply:

$data="YOUR IMAGE DATA";
file_put_contents("test.jpg",$data);