{"id":1902,"date":"2012-07-04T14:32:12","date_gmt":"2012-07-04T05:32:12","guid":{"rendered":"http:\/\/www.ka-net.org\/blog\/?p=1902"},"modified":"2012-07-04T14:32:12","modified_gmt":"2012-07-04T05:32:12","slug":"favicon%e3%82%92%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89%e3%81%99%e3%82%8b%e3%83%9e%e3%82%af%e3%83%ad","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=1902","title":{"rendered":"Favicon\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u30de\u30af\u30ed"},"content":{"rendered":"<p>Web\u30b5\u30a4\u30c8\u304b\u3089Favicon\u3092\u629c\u304d\u51fa\u3059API\u304c\u3042\u3063\u305f\u306e\u3067\u65e9\u901f\u4f7f\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><strong>\u30fbFavatar<\/strong><br \/>\n<a href=\"https:\/\/favatar.mention.net\/\" title=\"Favatar\" target=\"_blank\">https:\/\/favatar.mention.net\/<\/a><\/p>\n<p><span style=\"color: #ff0000; font-weight: bold;\">\u203b \u4e0b\u8a18\u30de\u30af\u30ed\u306fAPI\u30ad\u30fc\u304c\u5fc5\u9808\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u300c<a href=\"https:\/\/favatar.mention.net\/\" title=\"Start using Favatar now!\" target=\"_blank\">Start using Favatar now!<\/a>\u300d\u304b\u3089API\u30ad\u30fc\u3092\u4e8b\u524d\u306b\u53d6\u5f97\u3057\u3066\u304f\u3060\u3055\u3044(\u53d6\u5f97\u5f8c\u30b3\u30fc\u30c9\u5185\u306e&#8221;ApiKey&#8221;\u306e\u5024\u3092\u5909\u66f4)\u3002<\/span><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPublic Sub Sample()\r\n  GetFavicon &quot;http:\/\/\u6e0b\u8c37\u99c5.jp\/&quot;, &quot;C:\\Test&quot;\r\n  MsgBox &quot;\u51e6\u7406\u304c\u7d42\u4e86\u3057\u307e\u3057\u305f\u3002&quot;\r\nEnd Sub\r\n\r\nPrivate Sub GetFavicon(ByVal Target As String, ByVal SaveFolderPath As String)\r\n'Favicon\u53d6\u5f97\r\n  Dim url As String\r\n  Dim js As String\r\n  Dim mimeType, data '\u8868\u793a\u7528\u30c0\u30df\u30fc\r\n  Const ApiKey As String = &quot;your_key&quot; 'API\u30ad\u30fc\r\n  \r\n  url = &quot;http:\/\/favatar.mention.net\/image?format=json&amp;api_key=&quot; &amp; ApiKey &amp; &quot;&amp;url=&quot; &amp; EncodeURL(Target)\r\n  js = &quot;&quot; '\u521d\u671f\u5316\r\n  On Error Resume Next\r\n  With CreateObject(&quot;MSXML2.XMLHTTP&quot;)\r\n    .Open &quot;GET&quot;, url, False\r\n    .send\r\n    If .Status = 200 Then js = .responseText\r\n  End With\r\n  On Error GoTo 0\r\n  If Len(js) &gt; 0 Then\r\n    If LCase$(Trim$(js)) &lt;&gt; &quot;null&quot; Then\r\n      js = &quot;(&quot; &amp; js &amp; &quot;)&quot;\r\n      With CreateObject(&quot;ScriptControl&quot;)\r\n        .Language = &quot;JScript&quot;\r\n        If Right$(SaveFolderPath, 1) &lt;&gt; Application.PathSeparator Then SaveFolderPath = SaveFolderPath &amp; Application.PathSeparator\r\n        SaveFavicon SaveFolderPath &amp; GetDomainName(Target) &amp; &quot;.&quot; &amp; GetExtension(.CodeObject.eval(js).mimeType), .CodeObject.eval(js).data\r\n      End With\r\n    End If\r\n  End If\r\nEnd Sub\r\n\r\nPrivate Sub SaveFavicon(ByVal SaveFilePath As String, ByVal base64dat As String)\r\n'Favicon\u4fdd\u5b58\r\n'http:\/\/d.hatena.ne.jp\/language_and_engineering\/20101022\/p1 \u53c2\u7167\r\n  Dim dat() As Byte\r\n  \r\n  If Len(Dir$(SaveFilePath)) &gt; 0 Then Kill SaveFilePath '\u30d5\u30a1\u30a4\u30eb\u3092\u4e8b\u524d\u306b\u524a\u9664\r\n  With CreateObject(&quot;Microsoft.XMLDOM&quot;).createElement(&quot;base64-node&quot;)\r\n    .DataType = &quot;bin.base64&quot;\r\n    .Text = base64dat\r\n    dat = .nodeTypedValue\r\n  End With\r\n  With CreateObject(&quot;ADODB.Stream&quot;)\r\n    .Type = 1\r\n    .Open\r\n    .Write dat\r\n    .SaveToFile SaveFilePath\r\n    .Close\r\n  End With\r\nEnd Sub\r\n\r\nPrivate Function GetDomainName(ByVal url As String) As String\r\n'\u30c9\u30e1\u30a4\u30f3\u540d\u53d6\u5f97\r\n  Dim v As Variant\r\n  \r\n  If InStr(url, &quot;https:\/\/&quot;) Then\r\n    v = Split(Replace(url, &quot;https:\/\/&quot;, &quot;&quot;), &quot;\/&quot;)\r\n  Else\r\n    v = Split(Replace(url, &quot;http:\/\/&quot;, &quot;&quot;), &quot;\/&quot;)\r\n  End If\r\n  GetDomainName = v(LBound(v))\r\nEnd Function\r\n\r\nPrivate Function GetExtension(ByVal mimeType As String) As String\r\n'\u62e1\u5f35\u5b50\u53d6\u5f97(\u5909\u63db\u30c6\u30fc\u30d6\u30eb\u306f\u9069\u5f53)\r\n  Dim ret As String\r\n  \r\n  Select Case mimeType\r\n    Case &quot;image\/x-icon&quot;: ret = &quot;ico&quot;\r\n    Case &quot;image\/png&quot;, &quot;image\/x-png&quot;: ret = &quot;png&quot;\r\n    Case &quot;image\/gif&quot;: ret = &quot;gif&quot;\r\n    Case &quot;image\/jpeg&quot;: ret = &quot;jpg&quot;\r\n    Case &quot;image\/bmp&quot;, &quot;image\/x-MS-bmp&quot;: ret = &quot;bmp&quot;\r\n    Case &quot;image\/tiff&quot;: ret = &quot;tif&quot;\r\n    Case &quot;image\/x-emf&quot;: ret = &quot;emf&quot;\r\n    Case &quot;image\/x-wmf&quot;: ret = &quot;wmf&quot;\r\n    Case Else: ret = &quot;ico&quot;\r\n  End Select\r\n  GetExtension = ret\r\nEnd Function\r\n\r\nPrivate Function EncodeURL(ByVal sWord As String) As String\r\n  With CreateObject(&quot;ScriptControl&quot;)\r\n    .Language = &quot;JScript&quot;\r\n    EncodeURL = .CodeObject.encodeURIComponent(sWord)\r\n  End With\r\nEnd Function<\/pre>\n<p>\u4e0a\u8a18<strong>GetFavicon<\/strong>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306f\u3001\u5f15\u6570\u3068\u3057\u3066\u5bfe\u8c61URL\u3068Favicon\u306e\u4fdd\u5b58\u5148\u30d5\u30a9\u30eb\u30c0\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306bFavicon\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3059\u308b\u3082\u306e\u3067\u3001Base64\u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u305fFavicon\u30d5\u30a1\u30a4\u30eb\u3092\u5143\u306e\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb\u306b\u5909\u63db\u3059\u308b\u51e6\u7406\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>VBA\u3067Base64\u30c7\u30b3\u30fc\u30c9\u3059\u308b\u51e6\u7406\u3092\u66f8\u3044\u305f\u3053\u3068\u304c\u7121\u304b\u3063\u305f\u306e\u3067\u8a66\u3057\u306b\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u304c\u3001\u6b63\u76f4\u540c\u69d8\u306e\u30b5\u30fc\u30d3\u30b9\u3067\u3042\u308b\u300c<a href=\"http:\/\/www.getfavicon.org\/\" title=\"getFavicon.org\" target=\"_blank\">getFavicon.org<\/a>\u300d\u3092\u5229\u7528\u3057\u305f\u65b9\u304c\u697d\u306bFavicon\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">Option Explicit\r\n\r\nPrivate Declare Function URLDownloadToFileA Lib &quot;urlmon&quot; (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long\r\n\r\nPublic Sub Sample2()\r\n  GetFavicon &quot;\/\/www.ka-net.org\/blog&quot;, &quot;C:\\Test\\&quot;, 16, &quot;ico&quot;\r\nEnd Sub\r\n\r\nPrivate Sub GetFavicon(ByVal Target As String, ByVal SaveFolderPath As String, Optional ByVal Size As Long = 16, Optional ByVal Ext As String = &quot;ico&quot;)\r\n  URLDownloadToFileA 0&amp;, &quot;http:\/\/www.getfavicon.org\/?url=&quot; &amp; Target &amp; &quot;\/favicon.&quot; &amp; Size &amp; &quot;.&quot; &amp; Ext, SaveFolderPath &amp; &quot;favicon.&quot; &amp; Ext, 0&amp;, 0&amp;\r\nEnd Sub<\/pre>\n<p>\u3053\u3061\u3089\u306fFavatar\u3068\u9055\u3063\u3066\u30d5\u30a1\u30a4\u30eb\u5f62\u5f0f\u3084\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u79c1\u304c\u8a66\u3057\u305f\u9650\u308a\u3067\u306fFavatar\u306e\u65b9\u304c\u5bfe\u5fdc\u30b5\u30a4\u30c8\u304c\u591a\u3044\u3088\u3046\u306b\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>VBA\u30de\u30af\u30ed\u3067Favicon\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u6a5f\u4f1a\u3082\u305d\u3046\u305d\u3046\u7121\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u8208\u5473\u304c\u3042\u308b\u65b9\u306f\u4e00\u5ea6\u8a66\u3057\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n(\u4e0a\u8a18\u30b3\u30fc\u30c9\u306f\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u884c\u3063\u3066\u3044\u307e\u305b\u3093\u306e\u3067\u3001\u5b9f\u88c5\u3059\u308b\u969b\u306f\u9069\u5b9c\u51e6\u7406\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002)<\/p>\n","protected":false},"excerpt":{"rendered":"Web\u30b5\u30a4\u30c8\u304b\u3089Favicon\u3092\u629c\u304d\u51fa\u3059API\u304c\u3042\u3063\u305f\u306e\u3067\u65e9\u901f\u4f7f\u3063\u3066\u307f\u307e\u3057\u305f\u3002 \u30fbFavatar https:\/\/favatar.mention.net\/ \u203b \u4e0b\u8a18\u30de\u30af\u30ed\u306fAPI\u30ad\u30fc\u304c\u5fc5\u9808\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u300cStart u [&hellip;]","protected":false},"author":1,"featured_media":7111,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,48,49],"tags":[63,65],"class_list":["post-1902","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-word-office","tag-excel","tag-word"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Excel.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-uG","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1902"}],"version-history":[{"count":5,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1902\/revisions"}],"predecessor-version":[{"id":1907,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1902\/revisions\/1907"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7111"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}