{"id":673,"date":"2020-09-04T13:00:00","date_gmt":"2020-09-04T04:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/09\/04\/carrierwave-upload-pages"},"modified":"2020-09-04T13:00:00","modified_gmt":"2020-09-04T04:00:00","slug":"carrierwave-upload-pages","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2020\/09\/04\/carrierwave-upload-pages\/","title":{"rendered":"CarrierWave\u306eversions\u3067PDF\u306e\u5404\u30da\u30fc\u30b8\u753b\u50cf\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3088\u3046\u3068\u3057\u3066\u30cf\u30de\u3063\u305f\u3053\u3068"},"content":{"rendered":"
<\/p>\n
\u571f\u5c45\u3067\u3059\u3002\u672c\u65e5\u306fRails\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3001CarrierWave\uff08\u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6a5f\u80fd\u3092\u63d0\u4f9b\u3059\u308bGem\uff09\u306e\u6a5f\u80fd\u3092\u4e00\u90e8\u8aa4\u3063\u3066\u4f7f\u3063\u3066\u3044\u305f\u305f\u3081\u306b\u30cf\u30de\u3063\u3066\u3057\u307e\u3063\u305f\u3053\u3068\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
CarrierWave\u3092\u4f7f\u3063\u3066PDF\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u3057\u3066\u3044\u308b\u30b7\u30b9\u30c6\u30e0\u3067\u3001\u65b0\u305f\u306bPDF\u306e\u5404\u30da\u30fc\u30b8\u3092\u753b\u50cf\u5316\u3057\u3066\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\uff08+\u8868\u793a\uff09\u3059\u308b\u3053\u3068\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n
\u753b\u50cf\u5316\u81ea\u4f53\u306f\u5143\u3005\u4eca\u56de\u306e\u5bfe\u5fdc\u3068\u306f\u7570\u306a\u308b\u7b87\u6240\u3067\u884c\u3063\u3066\u304a\u308a\u3001\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308bPDF\u306e\u5148\u982d\u30da\u30fc\u30b8\u306e\u307f\u5bfe\u8c61\u3068\u3057\u3066\u753b\u50cf\u5316\uff08\u30b5\u30e0\u30cd\u30a4\u30eb\u751f\u6210\uff09\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u3067\u3059\u306e\u3067\u3001\u4eca\u56de\u306f\u305d\u306e\u90e8\u5206\u306e\u5fdc\u7528\u3067\u3067\u304d\u308b\u306e\u3067\u306f\uff1f\u3068\u3044\u3046\u76ee\u8ad6\u898b\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n
CarrierWave\u306eUploader\u306b\u306fversions<\/strong>\u3068\u3044\u3046\u6a5f\u80fd\u304c\u3042\u308a\u3001\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066\u5225\u30d0\u30fc\u30b8\u30e7\u30f3\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002\u524d\u8ff0\u306e\u30b5\u30e0\u30cd\u30a4\u30eb\u306f\u3053\u306e\u6a5f\u80fd\u3092\u7528\u3044\u3066\u3044\u307e\u3057\u305f\u3002 \u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3084\u30d6\u30ed\u30b0\u8a18\u4e8b\u306a\u3069\u3092\u898b\u3066\u3044\u308b\u9650\u308a\u3001versions\u306f\u3042\u3089\u304b\u3058\u3081\u5fc5\u8981\u306a\u3082\u306e\u3092Uploader\u5185\u306b\u540d\u524d\u4ed8\u304d\u3067\u5b9a\u7fa9\u3057\u3066\u304a\u304f\u3082\u306e\u306e\u3088\u3046\u3067\u3057\u305f\u304c\u3001version\u95a2\u6570\u3092\u52d5\u7684\u306b\u547c\u3073\u51fa\u3057\u3066\u3084\u308c\u3070\u30da\u30fc\u30b8\u3054\u3068\u306eversion\u3068\u3057\u3066\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3067\u304d\u308b\u306e\u3067\u306f\uff1f\u3068\u5b9f\u88c5\u3057\u3001\u5b9f\u969b\u306b\u624b\u5143\u3067\u306f\u3046\u307e\u304f\u3044\u3063\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n \u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3042\u308bversion\u306e\u66f8\u304d\u65b9\u3002 \u4eca\u56de\u3084\u308d\u3046\u3068\u3057\u305f\u66f8\u304d\u65b9\u3002 \u3072\u3068\u3068\u304a\u308a\u306e\u30c6\u30b9\u30c8\u3092\u3057\u305f\u306e\u3061\u3001\u30c7\u30d7\u30ed\u30a4\u3057\u305f\u74b0\u5883\u3067\u52d5\u4f5c\u78ba\u8a8d\u3092\u3059\u308b\u3068\u753b\u50cf\u751f\u6210\u304c\u3067\u304d\u3066\u3044\u306a\u3044\u3053\u3068\u3084\u3001\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6642\u306b\u30b5\u30fc\u30d0\u30fc\u30a8\u30e9\u30fc\u3067\u843d\u3061\u3066\u3057\u307e\u3046\u306a\u3069\u306e\u554f\u984c\u304c\u8d77\u304d\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002 \u554f\u984c\u306e\u8d77\u304d\u308b\u74b0\u5883\u306f2\u53f0\u69cb\u6210\u3067\u3042\u308a\u3001\u3069\u3046\u3082\u305d\u3053\u306b\u4e0d\u5b89\u5b9a\u306a\u52d5\u4f5c\u306e\u539f\u56e0\u304c\u3042\u308b\u3088\u3046\u3067\u3057\u305f\u3002 \u7d50\u5c40\u3001CarrierWave\u306eversion\u306f\u3042\u3089\u304b\u3058\u3081\u6c7a\u307e\u3063\u305f\u3082\u306e\u3092\u5b9a\u7fa9\u3057\u3066\u304a\u304f\u3082\u306e\u3067\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u64cd\u4f5c\u306b\u3088\u3063\u3066\u52d5\u7684\u306b\u66f4\u65b0\u3059\u308b\u306e\u306f\u53b3\u3057\u3044\u306e\u3060\u3068\u601d\u3044\u307e\u3057\u305f\u3002\uff08\u3069\u3046\u3057\u3066\u3082\u5f8c\u304b\u3089\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u306f\u30b5\u30fc\u30d0\u30fc\u306b\u5165\u3063\u3066\u76f4\u63a5\u3001rails c\u3067model\u306b\u5bfe\u3057\u3066recreate_versions!\u95a2\u6570<\/a>\u3092\u7528\u3044\u308c\u3070versions\u306e\u518d\u4f5c\u6210\u3059\u308b\u3053\u3068\u306f\u53ef\u80fd\u306a\u3088\u3046\u3067\u3059\uff09<\/p>\n versions\u3092\u4f7f\u308f\u306a\u3044\u3053\u3068\u3092\u6c7a\u3081\u3001\u4ee5\u4e0b\u306e\u9078\u629e\u80a2\u3092\u8003\u3048\u307e\u3057\u305f\u3002<\/p>\n 2\u306f\u4e00\u90e8\u6a5f\u80fd\u3068\u306f\u3044\u3048\u3001\u305b\u3063\u304b\u304f\u5197\u9577\u5316\u3057\u3066\u3044\u308b\u306e\u3092\u3084\u3081\u308b\u306e\u306f\u3088\u304f\u306a\u3044\u3002 Shrine\u3068\u3044\u3046\u5225\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c0\u30fc\u3092\u7528\u3044\u308b\u3068\u3001\u52d5\u7684\u306aversion\u3082\u7c21\u5358\u306b\u3067\u304d\u308b\u3002\u3068\u3044\u3046\u3088\u3046\u306a\u3053\u3068\u3092\u76ee\u306b\u3057\u305f\u306e\u3067\u3001 https:\/\/github.com\/carrierwaveuploader\/carrierwave<\/a> \u571f\u5c45\u3067\u3059\u3002\u672c\u65e5\u306fRails\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3001CarrierWave\uff08\u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u6a5f\u80fd\u3092\u63d0\u4f9b\u3059\u308bGem\uff09\u306e\u6a5f\u80fd\u3092\u4e00\u90e8\u8aa4\u3063\u3066\u4f7f\u3063\u3066\u3044\u305f\u305f\u3081\u306b\u30cf\u30de\u3063\u3066\u3057\u307e\u3063\u305f\u3053\u3068\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 PDF\u306e\u5404\u30da\u30fc\u30b8\u3092\u753b\u50cf\u5316\u3057\u3066\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9 CarrierWave\u3092\u4f7f\u3063\u3066PDF\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u3057\u3066\u3044\u308b\u30b7\u30b9\u30c6\u30e0\u3067\u3001\u65b0\u305f\u306bPDF\u306e\u5404\u30da\u30fc\u30b8\u3092\u753b\u50cf\u5316\u3057\u3066\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\uff08+\u8868\u793a\uff09\u3059\u308b\u3053\u3068\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3057\u305f\u3002 \u753b\u50cf […]<\/p>\n","protected":false},"author":11,"featured_media":684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9,17],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/673"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=673"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/673\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\nversion\u3092\u8ffd\u52a0<\/a><\/p>\nPDF\u306e\u30da\u30fc\u30b8\u3054\u3068\u306bversions\u751f\u6210<\/h1>\n
\nversion\u306f**:thumb**\u306e\u56fa\u5b9a<\/p>\nclass MyUploader < CarrierWave::Uploader::Base\n include CarrierWave::MiniMagick\n\n process resize_to_fit: [800, 800]\n\n version :thumb do\n process resize_to_fill: [200,200]\n end\nend<\/code><\/pre>\n
\n\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305fPDF\u30d5\u30a1\u30a4\u30eb\u306e\u30da\u30fc\u30b8\u6570\u3067\u30eb\u30fc\u30d7\u3057\u3001version\u95a2\u6570\u30921\u30da\u30fc\u30b8\u3054\u3068\u306b\u547c\u3073\u51fa\u3057\u3066\u3044\u308b\u3002
\nversion\u304c1, 2, 3\u3068\u30da\u30fc\u30b8\u3054\u3068\u306b\u751f\u6210\u3055\u308c\u308b\u3002<\/p>\nclass MyUploader < CarrierWave::Uploader::Base\n include CarrierWave::MiniMagick\n\n process convert_pages\n\n def convert_pages\n def convert_pages\n # \u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u30d5\u30a1\u30a4\u30eb\u306e\u30da\u30fc\u30b8\u6570\u3092\u53d6\u5f97\n pages = Magick::Image.read(current_path).length\n\n # \u30da\u30fc\u30b8\u6570\u306e\u5206\u3001version\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\n (1..pages).each do |page|\n MyUploader.version :"#{page}" do\n # convert_to_image\u306f\u5f15\u6570\u3067\u4e0e\u3048\u305f\u8a72\u5f53\u30da\u30fc\u30b8\u3092\u753b\u50cf\u5316\u3059\u308b\u95a2\u6570\n process convert_to_image: [page]\n process convert: :png\n\n def full_filename(for_file)\n super(for_file).sub(\/.pdf\/, '.png')\n end\n end\n end\n end\n end\nend<\/code><\/pre>\n
\u30c7\u30d7\u30ed\u30a4\u3057\u3066\u52d5\u4f5c\u3055\u305b\u308b\u3068\u554f\u984c\u767a\u751f<\/h1>\n
\n\u3069\u3046\u3057\u3066\u3060\u308d\u3046\uff1f\u554f\u984c\u304c\u6bce\u56de\u8d77\u304d\u308b\u308f\u3051\u3067\u306f\u306a\u304f\u5b89\u5b9a\u611f\u304c\u306a\u3044\u3053\u3068\u3084\u3001\u30c7\u30d7\u30ed\u30a4\u3057\u3066\u30b5\u30fc\u30d0\u30fc\u518d\u8d77\u52d5\u6642\u306b\u306f\u5fc5\u305a\u8d77\u304d\u308b\u306a\u3069\u306e\u73fe\u8c61\u3082\u898b\u3089\u308c\u307e\u3057\u305f\u3002<\/p>\n\u5197\u9577\u5316\u69cb\u6210\u3060\u3068\u8d77\u304d\u308b<\/h1>\n
\nCarrierWave\u306eversions\u306f\u30af\u30e9\u30b9\u5909\u6570\u3068\u3057\u3066\u4fdd\u6301\u3055\u308c\u3066\u304a\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u3068\u304d\u306b\u5411\u3044\u3066\u3044\u305f\u7cfb\u306b\u3057\u304bversions\uff08\u30d5\u30a1\u30a4\u30eb\u306e\u30da\u30fc\u30b8\u6570\u306b\u3088\u3063\u3066\u5909\u5316\u3059\u308b\uff09\u304c\u53cd\u6620\u3055\u308c\u3066\u3044\u306a\u304b\u3063\u305f\u306e\u3067\u3059\u3002
\n\u307e\u305f\u3001\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u306f\u3069\u3053\u304b\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u4e00\u5ea6\u4fdd\u6301\u3055\u308c\u305fversions\u304c\u6b8b\u3063\u3066\u3044\u305f\u305f\u3081\u753b\u50cf\u751f\u6210\u304c\u3067\u304d\u3066\u3044\u305f\u3088\u3046\u3067\u3059\u304c\u3001\u30b5\u30fc\u30d0\u30fc\u304c\u518d\u8d77\u52d5\u3059\u308b\u305f\u3073\u306bversions\u306f0\u500b\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3068\u8003\u3048\u3089\u308c\u307e\u3059\uff08\u79c1\u306eUploader\u3067\u306f\u3001\u5b9f\u969b\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u307e\u3067version\u304c\u751f\u6210\u3055\u308c\u306a\u3044\u305f\u3081\uff09\u3002\u305d\u306e\u305f\u3081\u3001\u30c7\u30d7\u30ed\u30a4\u76f4\u5f8c\u306e\u521d\u56de\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u306f\u5fc5\u305a\u5931\u6557\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\nversions\u306f\u4eca\u56de\u306e\u7528\u9014\u306b\u9069\u3055\u306a\u3044<\/h1>\n
\u5bfe\u5fdc<\/h1>\n
\n
\n\u307e\u305f\u30013\u306f\u3067\u304d\u305d\u3046\u3067\u3057\u305f\u304c\u3042\u307e\u308a\u306b\u3082\u52d5\u4f5c\u304c\u91cd\u3059\u304e\u307e\u3057\u305f\u3002
\n\u7d50\u679c\u30011\u3092\u63a1\u308b\u3053\u3068\u306b\u3002
\nRMagick\u3067\u753b\u50cf\u5316\u3057\u3001aws-sdk\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u5f62\u3068\u3057\u307e\u3057\u305f\u3002<\/p>\n\u6b21\u56de\u306f<\/h1>\n
\n\u5168\u4f53\u7684\u306bCarrierWave\u304b\u3089\u7f6e\u304d\u63db\u3048\u3066\u307e\u3067\u3084\u308b\u3079\u304d\u304b\u3068\u3044\u3046\u306e\u3082\u3042\u308b\u306e\u3067\u3001\u5225\u306e\u65b0\u898f\u30b5\u30fc\u30d3\u30b9\u306a\u3069\u6a5f\u4f1a\u304c\u3042\u308c\u3070\u8a66\u3057\u305f\u3044\u3067\u3059\u306d\u3002<\/p>\n\u53c2\u8003<\/h1>\n
\nhttps:\/\/github.com\/rmagick\/rmagick<\/a>
\nhttps:\/\/github.com\/shrinerb\/shrine<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"