简体   繁体   English

图片未显示在img标签中

[英]Image not showing up in img tag

I am working on using the OMDB API and I get the url of the poster of a movie. 我正在使用OMDB API,并且获得了电影海报的网址。

For example: https://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg 例如: https : //ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg

When you view that image in the browser by clicking on the link, it is perfectly visible. 通过单击链接在浏览器中查看该图像时,该图像完全可见。 But when I use it in an img tag, it does not find the image: 但是当我在img标签中使用它时,它找不到图像:

<img src="https://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg">

Here the above code implemented: 这里上面的代码实现了:

Can anyone help me out? 谁能帮我吗?

IMDB blocks direct linking of the images from other sites (as yours). IMDB阻止来自其他站点(如您自己)的图像的直接链接。 So linking the url you get from the response will lead to the "Referral Denied" message and the image not showing. 因此,将您从响应中获得的URL链接起来将导致出现“ Referral Denied”消息,并且图像未显示。

However, OMDB seems to have the new Poster API that self-rehosts the images, but a donation is required to use it as evident on the site: 但是,OMDB似乎具有新的Poster API,可以重新托管图像,但是需要捐赠才能使用它,在网站上很明显:

New Poster API The Poster API is currently in beta being tested by the sites friendly donators. 新的海报API海报API目前处于Beta版,正在由站点友好的捐赠者进行测试。

Donators get your key and start testing! 捐赠者拿到您的钥匙并开始测试!

and

1/1/15 15年1月1日

  • You can now search by type! 您现在可以按类型搜索! (movie, series, episode etc.) Dupes (电影,系列,剧集等)
  • have been removed from database. 已从数据库中删除。
  • Poster API images updated. 海报API图片已更新。

If you are looking for a way to display these images you can create a php file that returns the image data and just link to it like so 如果您正在寻找一种显示这些图像的方法,则可以创建一个php文件来返回图像数据,然后像这样链接到它

<img src='link/to/php/image.php?i=imdb-image.jpg'/>

image.php image.php

<?php
    $img = $_REQUEST['i'];
    $image_mime = getimagesize($img)['mime'] ;
    header("Content-type: " .$image_mime);
    echo file_get_contents($img);
?>

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

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