[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

displaying gziped image



青田です。

gzipエンコードされた画像をデコードせず、またデコードしてもContent-Typeが正しいか
どうかのチェックをデコード前に行なっているため、そのような画像が表示できていません。
(はてなダイアリーの、ログインしていない状態でコメントするのに必要なcaptcha画像が
gzipされていて、かつContent-Typeがおかしいちょうどいいサンプルになっています。)

パッチでno-decode => 'rawで取得しているところをnilにし、gzipデコード後に
Content-Typeを無理矢理修正してあります。
;; ほんとに無理矢理ですがとりあえず動いてるようです

ところで、no-decodeの意味がいまいちわからないのですが、gzipなどのデコードを回避する
だけのオプションなのでしょうか?

Index: ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/ChangeLog,v
retrieving revision 1.3016
diff -u -r1.3016 ChangeLog
--- ChangeLog	7 Jun 2007 12:21:51 -0000	1.3016
+++ ChangeLog	7 Jun 2007 15:29:50 -0000
@@ -1,3 +1,13 @@
+2007-06-08  Naohiro Aota  <nao.aota@xxxxxxxxx>
+
+	* w3m.el (w3m-w3m-retrieve): Check if content-type is wrong after
+	decoding encoded contents.
+	
+	* w3m-ems.el (w3m-create-image, w3m-create-resized-image): Decode
+	content retrieving image.
+
+	* w3m-xmas.el (w3m-create-image, w3m-create-resized-image):Ditto.
+
 2007-06-07  Naohiro Aota  <nao.aota@xxxxxxxxx>
 
 	* w3m-search.el (w3m-search-engine-alist): Add output encoding argument
Index: w3m-ems.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-ems.el,v
retrieving revision 1.15
diff -u -r1.15 w3m-ems.el
--- w3m-ems.el	17 May 2007 02:25:44 -0000	1.15
+++ w3m-ems.el	7 Jun 2007 15:29:55 -0000
@@ -210,7 +210,7 @@
       (w3m-process-do-with-temp-buffer
 	  (type (progn
 		  (set-buffer-multibyte nil)
-		  (w3m-retrieve url 'raw no-cache nil referer handler)))
+		  (w3m-retrieve url nil no-cache nil referer handler)))
 	(when (w3m-image-type-available-p (setq type (w3m-image-type type)))
 	  (setq image (create-image (buffer-string) type t :ascent 'center))
 	  (if (and w3m-resize-images set-size)
@@ -254,7 +254,7 @@
       (w3m-process-do-with-temp-buffer
 	  (type (progn
 		  (set-buffer-multibyte nil)
-		  (w3m-retrieve url 'raw nil nil referer handler)))
+		  (w3m-retrieve url nil nil nil referer handler)))
 	(when (w3m-image-type-available-p (setq type (w3m-image-type type)))
 	  (setq image (create-image (buffer-string) type t :ascent 'center))
 	  (progn
Index: w3m-xmas.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-xmas.el,v
retrieving revision 1.137
diff -u -r1.137 w3m-xmas.el
--- w3m-xmas.el	26 Mar 2007 23:14:21 -0000	1.137
+++ w3m-xmas.el	7 Jun 2007 15:30:06 -0000
@@ -387,7 +387,7 @@
 		  size)
       (w3m-process-do-with-temp-buffer
 	  (type (condition-case err
-		    (w3m-retrieve url 'raw no-cache nil referer handler)
+		    (w3m-retrieve url nil no-cache nil referer handler)
 		  (error (message "While retrieving %s: %s" url err) nil)))
 	(when type
 	  (let ((data (buffer-string))
@@ -441,7 +441,7 @@
 		  (rate rate)
 		  fmt data)
       (w3m-process-do-with-temp-buffer
-	  (type (w3m-retrieve url 'raw nil nil referer handler))
+	  (type (w3m-retrieve url nil nil nil referer handler))
 	(when (w3m-image-type-available-p (setq type (w3m-image-type type)))
 	  (setq data (buffer-string)
 		fmt type)
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1281
diff -u -r1.1281 w3m.el
--- w3m.el	17 May 2007 22:31:43 -0000	1.1281
+++ w3m.el	7 Jun 2007 15:30:46 -0000
@@ -4943,7 +4943,20 @@
 	    (let ((temp-buffer (current-buffer)))
 	      (with-current-buffer current-buffer
 		(insert-buffer-substring temp-buffer))
-	      (cadr attr))
+	      (goto-char (point-min))
+	      ;; Asahi-shimbun sometimes says gif as jpeg mistakenly, for
+	      ;; example.  So, we cannot help trusting the data itself.
+	      (if (and (string-match "^image/" (cadr attr))
+		       (prog2
+			   (setq case-fold-search nil)
+			   (looking-at "\\(GIF8\\)\\|\\(\377\330\\)\\|\211PNG\r\n")
+			 (setq case-fold-search t)))
+		  (progn
+		    (concat "image/"
+			    (cond ((match-beginning 1) "gif")
+				  ((match-beginning 2) "jpeg")
+				  (t "png"))))
+		(cadr attr)))
 	  (ding)
 	  (w3m-message "Can't decode encoded contents: %s" url)
 	  nil)))))