{"id":5616,"date":"2018-09-21T11:17:43","date_gmt":"2018-09-21T02:17:43","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=5616"},"modified":"2020-05-28T13:22:02","modified_gmt":"2020-05-28T04:22:02","slug":"java-thumbnail-image-%eb%a7%8c%eb%93%9c%eb%8a%94-%ec%bd%94%eb%93%9c","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=5616","title":{"rendered":"[Java] Thumbnail Image \ub9cc\ub4dc\ub294 \ucf54\ub4dc"},"content":{"rendered":"<p>\ucf54\ub4dc \uc815\ub9ac\ud558\ub2e4\uac00 \ube14\ub85c\uadf8\uc5d0 \uc815\ub9ac\ub418\uc9c0 \uc54a\uc740 \ucf54\ub4dc\uac00 \uc788\uc5b4 \uc815\ub9ac\ud574 \ubd05\ub2c8\ub2e4. \uc77c\ubc18\uc801\uc778 \uc774\ubbf8\uc9c0\ub97c \uc791\uc740 \uc774\ubbf8\uc9c0, \uc989 \uc378\ub124\uc77c \uc774\ubbf8\uc9c0\ub85c \ub9cc\ub4e4\uc5b4 \uc8fc\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4. \uc774\ubbf8\uc9c0\uc758 \uc885\ud6a1\ube44 \ud06c\uae30\ub97c \uc720\uc9c0\ud558\uba70 \uc378\ub124\uc77c \uc774\ubbf8\uc9c0\ub97c \ub9cc\ub4e4\uc5b4 \uc90d\ub2c8\ub2e4. \uc378\ub124\uc77c \uc774\ubbf8\uc9c0 \ub9cc\ub4dc\ub294 \ucf54\ub4dc\ub97c \uc2e4\uc81c \ud504\ub85c\uc81d\ud2b8\uc5d0 \ubd99\uc774\uae30 \uc704\ud574 \ub9cc\ub4e4\ub2e4 \ubcf4\ub2c8, \ubd80\uac00\uc801\uc778 \ub0b4\uc6a9\uc774 \ub367\ubd99\uc5ec \uc788\uc73c\ub2c8 \ucc38\uace0\ud558\uc2dc\uae30 \ubc14\ub78d\ub2c8\ub2e4.<\/p>\n<p>\uc0ac\uc6a9\uc740 \uc544\ub798\ucc98\ub7fc \ud558\uba74 \ub429\ub2c8\ub2e4. \uc989, d:\/a.jpg \ud30c\uc77c\uc744 \uc378\ub124\uc77c \uc774\ubbf8\uc9c0\ub97c \ub9cc\ub4dc\ub294\ub370, \uac00\ub85c \ub610\ub294 \uc138\ub85c \ud06c\uae30 \uc911 \ud558\ub098\ub97c 256\uc744 \ub9cc\ub4ed\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\nreateThumbnail(\"d:\/a.jpg\", 256);\r\n<\/pre>\n<p>\uc544\ub798\ub294 d:\/a.jpg\uc758 \uc2e4\uc81c \uc774\ubbf8\uc9c0\uc785\ub2c8\ub2e4. \uc774\ubbf8\uc9c0 \ud06c\uae30\ub294 920&#215;600\uc785\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2018\/09\/a.jpg\" width=\"920\" height=\"600\" class=\"aligncenter\" \/><\/p>\n<p>\uc704\uc758 \uc774\ubbf8\uc9c0\uac00 \uc704\uc758 \ucf54\ub4dc\ub97c \ud1b5\ud574 \uc544\ub798\uc640 \uac19\uc774 d:\/a.thumbnail.jpg \ud30c\uc77c\ub85c \ub9cc\ub4e4\uc5b4\uc9c0\uace0 \ud06c\uae30\ub294  256&#215;166\uc774 \ub429\ub2c8\ub2e4. \uc6d0\ubcf8 \uc774\ubbf8\uc9c0\uc758 \uac00\ub85c \ud06c\uae30\uac00 \uc138\ub85c\ubcf4\ub2e4 \uae38\ub2e4\ubcf4\ub2c8 \uac00\ub85c\ub97c 256\uc73c\ub85c \ub9cc\ub4e4\uc5b4\uc9c0\uac8c \ub418\ub294 \uac83\uc785\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2018\/09\/a.thumbnail.jpg\" width=\"256\" height=\"166\" class=\"aligncenter\" \/><\/p>\n<p>createThumbnail \ud568\uc218\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\nprivate static boolean createThumbnail(String fileName, int maxSize) {\r\n    try {\r\n        int thumbnail_width = maxSize;\r\n        int thumbnail_height = maxSize;\r\n\r\n        File origin_file_name = new File(fileName);\r\n\t\t    \r\n        String ext = getFileExt(fileName);\r\n        String newFileName = fileName.replace(\".\" + ext, \".thumbnail.\" + ext);\r\n\t\t    \r\n        BufferedImage buffer_original_image = ImageIO.read(origin_file_name);\r\n\t\t    \r\n        double imgWidth = buffer_original_image.getWidth();\r\n        double imgHeight = buffer_original_image.getHeight();\r\n\t\t    \r\n        if(imgWidth < imgHeight) {\r\n            thumbnail_width = (int)((imgWidth \/ imgHeight) * maxSize);\r\n        } else {\r\n            thumbnail_height = (int)((imgHeight \/ imgWidth) * maxSize);\r\n        }\r\n\t\t    \r\n        int imgType = (buffer_original_image.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;\r\n        BufferedImage buffer_thumbnail_image = new BufferedImage(thumbnail_width, thumbnail_height, imgType);\r\n        Graphics2D graphic = buffer_thumbnail_image.createGraphics();\r\n\t\t    \r\n        graphic.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);\r\n        graphic.drawImage(buffer_original_image, 0, 0, thumbnail_width, thumbnail_height, null);\r\n\t\t    \r\n        if(ext.equalsIgnoreCase(\"jpg\")) {\r\n            writeJpeg(buffer_thumbnail_image, newFileName, 1.0f);\r\n        } else {\r\n            File thumb_file_name = new File(newFileName);\r\n            ImageIO.write(buffer_thumbnail_image, ext.toLowerCase(), thumb_file_name);\r\n        }\r\n\t\t    \r\n        graphic.dispose();\r\n    } catch (Exception e) {\r\n        e.printStackTrace(System.err);\r\n        return false;\r\n    }\r\n\t\t\r\n    return true;\r\n}\r\n<\/pre>\n<p>\uc704\uc758 \ud568\uc218\ub294 2\uac1c\uc758 \ub0b4\ubd80 \ud568\uc218\ub97c \ud638\ucd9c\ud558\uace0 \uc788\ub294\ub370, \ud574\ub2f9\ub418\ub294 \ud568\uc218\ub4e4\uc740 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">\r\nprivate static String getFileExt(String fileName) { \/\/ \"abc.txt\" -> \"txt\", not \".txt\"\r\n    int i = fileName.lastIndexOf('.');\r\n    int p = Math.max(fileName.lastIndexOf('\/'), fileName.lastIndexOf('\\\\'));\r\n\r\n    if (i > p) {\r\n        return fileName.substring(i+1);\r\n    }\r\n\r\n    return null;\r\n}\r\n\t \r\nprivate static void writeJpeg(BufferedImage image, String destFile, float quality) throws IOException {\r\n    ImageWriter writer = null;\r\n    FileImageOutputStream output = null;\r\n\t\t  \r\n    try {\r\n        writer = ImageIO.getImageWritersByFormatName(\"jpeg\").next();\r\n\t\r\n        ImageWriteParam param = writer.getDefaultWriteParam();\r\n\t\t    \r\n        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);\r\n        param.setCompressionQuality(quality);\r\n\t\t    \r\n        output = new FileImageOutputStream(new File(destFile));\r\n        writer.setOutput(output);\r\n\t\t    \r\n        IIOImage iioImage = new IIOImage(image, null, null);\r\n        writer.write(null, iioImage, param);\r\n    } catch (IOException ex) {\r\n        throw ex;\r\n    } finally {\r\n        if (writer != null) {\r\n            writer.dispose();\r\n        }\r\n\t\t    \r\n        if (output != null) {\r\n            output.close();\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>\ub2e8\uc704 \ud14c\uc2a4\ud2b8\ub85c \ub9cc\ub4e4\uc5b4 \ub193\uc740 \ucf54\ub4dc\uc778\uc9c0\ub77c \ucd5c\uc801\ud654\uac00 \ub418\uc5b4 \uc788\uc9c0 \uc54a\uc73c\ub2c8, \uc0b4\ud3b4\ubcf4\uc2dc\uace0 \ucd5c\uc801\ud654 \ud574 \uc0ac\uc6a9\ud558\uc2dc\uae30 \ubc14\ub78d\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ucf54\ub4dc \uc815\ub9ac\ud558\ub2e4\uac00 \ube14\ub85c\uadf8\uc5d0 \uc815\ub9ac\ub418\uc9c0 \uc54a\uc740 \ucf54\ub4dc\uac00 \uc788\uc5b4 \uc815\ub9ac\ud574 \ubd05\ub2c8\ub2e4. \uc77c\ubc18\uc801\uc778 \uc774\ubbf8\uc9c0\ub97c \uc791\uc740 \uc774\ubbf8\uc9c0, \uc989 \uc378\ub124\uc77c \uc774\ubbf8\uc9c0\ub85c \ub9cc\ub4e4\uc5b4 \uc8fc\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4. \uc774\ubbf8\uc9c0\uc758 \uc885\ud6a1\ube44 \ud06c\uae30\ub97c \uc720\uc9c0\ud558\uba70 \uc378\ub124\uc77c \uc774\ubbf8\uc9c0\ub97c \ub9cc\ub4e4\uc5b4 \uc90d\ub2c8\ub2e4. \uc378\ub124\uc77c \uc774\ubbf8\uc9c0 \ub9cc\ub4dc\ub294 \ucf54\ub4dc\ub97c \uc2e4\uc81c \ud504\ub85c\uc81d\ud2b8\uc5d0 \ubd99\uc774\uae30 \uc704\ud574 \ub9cc\ub4e4\ub2e4 \ubcf4\ub2c8, \ubd80\uac00\uc801\uc778 \ub0b4\uc6a9\uc774 \ub367\ubd99\uc5ec \uc788\uc73c\ub2c8 \ucc38\uace0\ud558\uc2dc\uae30 \ubc14\ub78d\ub2c8\ub2e4. \uc0ac\uc6a9\uc740 \uc544\ub798\ucc98\ub7fc \ud558\uba74 \ub429\ub2c8\ub2e4. \uc989, d:\/a.jpg \ud30c\uc77c\uc744 \uc378\ub124\uc77c \uc774\ubbf8\uc9c0\ub97c \ub9cc\ub4dc\ub294\ub370, \uac00\ub85c \ub610\ub294 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=5616\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[Java] Thumbnail Image \ub9cc\ub4dc\ub294 \ucf54\ub4dc&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[60],"tags":[],"class_list":["post-5616","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/5616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5616"}],"version-history":[{"count":6,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/5616\/revisions"}],"predecessor-version":[{"id":9576,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/5616\/revisions\/9576"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5616"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}