I opened a image/x-png type image in new tab, but Chrome just downloaded it. I googled it and found that Chrome doesn\'t interpret image/x-png as image fil
Too bad you have not answered my comment, so I forgot about your question and lost the bounty. I guess my answer is even a little easier to use for you because you do not need to click any context menus in order to see the PNGs directly in the browser:
Chrome extension Redirector can be configured to replace HTTP response headers. I created a rule replacing the Content-Type header for any URL ending with ".png":
Paste this JSON code into a text editor, save as png_rule.json and then in Redirector settings go to Rules Manager, click Files to open im-/export options and import the rule version 1:
[{"name":"x-png -> png","match":{"str":"\\.png$","type":0,"modi":false},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/png","decode":false},"enabled":1}]
From now on all your PNG files should be fine.
Update: replaced the simple pattern match by a stricter regex match as suggested by the author or Redirector.
Update 2: There are systems like Trac which produce URLs for PNG attachments ending in ".png", but really being HTML pages which only embed the PNG as part of the page. In this case we need to blacklist the hosts because otherwise the HTML page's content type would be set to image/png even though it should remain text/html. Because of Redirector's limitation that headers can just be overwritten for matched URLs and partial replacement, e.g. only png instead of x-png, is impossible, we need to use a rather ugly approach of explicitly excluding certain hosts in the regex match. E.g.
^https?://(?!([^/]+\.)?(?:trac\.edgewall\.org|freetz\.org)/).*\.png$
would exclude URLs containing either host name trac.edgewall.org or freetz.org. The full JSON to be imported into Redirector is rule version 2:
[{"name":"x-png -> png","match":{"str":"^https?://(?!([^/]+\\.)?(?:trac\\.edgewall\\.org|freetz\\.org)/).*\\.png$","type":0,"modi":true},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/png","decode":false},"enabled":1}]
Two test URLs failing (i.e. showing empty "images" instead of HTML pages) with the previous version of the rule without blacklisting and now functioning with the new rule including blacklisting are:
It is easy to add other URLs if you know a little regex or just play around.
By the way: For Trac URLs a good alternative would be to use the common part "/attachment/ticket/" for blacklisting. This way you could blacklist all Trac installations worldwide instead of a fixed hosts list. So this is rule version 3:
[{"name":"x-png -> png","match":{"str":"^https?://(?!([^/]+)?/attachment/ticket/).*\\.png$","type":0,"modi":true},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/png","decode":false},"enabled":1}]
Update 3: Redirector is no longer available in Chrome store, but historic versions can be downloaded from the old Redirector home page.
Apparently, Chrome does not have its own mime-handling database, but uses that of your desktop environment.
In my XFCE4-based environment, for example, the settings are controlled through the xfce4-settings
app (xfce4-mime-settings
specifically).
On a Windows desktop, you'd go through the "Default Programs" part of the "Control Panel", as described in (painful) detail here.
It seems that you can't edit your MIME type mappings, see "View As MIME Type" in Chrome or Firefox
This answer https://stackoverflow.com/a/8724758/962091 is of particular interest. The author has made and open sourced a Chrome extension to open files as different MIME types via an added menu item on right-click, though it does not provide a global handling mechanism.
EDIT:
The extension by default only has the options to open as text/html
and text/plain
, but you can add any extensions you like, including image/png
, in the extensions settings. Here's a test image.
This bug was moved to Untriaged on August 13, 2012 in the Chromium bug tracker, so hopefully this will be fixed soon in Chrome as well.
There is a Chrome extension that can change the content-type and the disposition for any pattern, so it can be used to force png to display instead of download (but it is good for many other cases, I am using it to render txt as HTML): Modify Content-Type Chrome Extension
For some reason they have removed redirector from chrome web shop. You can find any version of redirector here
Here is json for .jpg .gif and .png formats:
[{"name":"x-png -> png","match":{"str":"\.png$","type":0,"modi":false},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/png","decode":false},"enabled":1},{"name":"x-jpg -> jpg","match":{"str":"\.jpg$","type":0,"modi":false},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/jpg","decode":false},"enabled":1},{"name":"x-gif -> gif","match":{"str":"\.gif$","type":0,"modi":false},"sub":{"str":"Content-Type","type":4,"modi":true,"modg":true},"repl":{"str":"image/gif","decode":false},"enabled":1}]