diff --git a/Graphics/Thumbnail.hs b/Graphics/Thumbnail.hs
new file mode 100644
--- /dev/null
+++ b/Graphics/Thumbnail.hs
@@ -0,0 +1,76 @@
+module Graphics.Thumbnail
+       ( ImageFormat(..)
+       , Thumbnail(..)
+       , mkThumbnail) where
+
+import Graphics.GD
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Lazy as L
+
+data ImageFormat = Gif | Jpeg | Png
+
+data Thumbnail = Thumbnail { fmt :: ImageFormat
+                           , img :: Image
+                           , sz  :: Size
+                           , lbs :: L.ByteString
+                           }
+
+mkThumbnail :: L.ByteString -> IO Thumbnail
+mkThumbnail = thumbnail . L.unpack
+  where
+    thumbnail ws@(0xff:0xd8:_) = thumbnailJpeg ws
+    thumbnail ws@(0x89:0x50:_) = thumbnailPng ws
+    thumbnail ws@(0x47:0x49:0x46:_) = thumbnailGif ws
+    thumbnail _ = error "unsupported image format"
+    
+    thumbnailJpeg ws = do
+      src <- loadJpegByteString $ BS.pack ws
+      size <- imageSize src
+      dest <- copyImage src
+      let size' = newSize size
+      thm <- uncurry resizeImage size' dest
+      bs <- saveJpegByteString (-1) thm
+      return Thumbnail { fmt=Jpeg
+                       , img=thm
+                       , sz=size'
+                       , lbs=strictToLazy bs
+                       }
+    
+    thumbnailPng ws = do
+      src <- loadPngByteString $ BS.pack ws
+      size <- imageSize src
+      dest <- copyImage src
+      let size' = newSize size
+      thm <- uncurry resizeImage size' dest
+      bs <- savePngByteString thm
+      return Thumbnail { fmt=Png
+                       , img=thm
+                       , sz=size'
+                       , lbs=strictToLazy bs
+                       }
+      
+    thumbnailGif ws = do
+      src <- loadGifByteString $ BS.pack ws
+      size <- imageSize src
+      dest <- copyImage src
+      let size' = newSize size
+      thm <- uncurry resizeImage size' dest
+      bs <- saveGifByteString thm
+      return Thumbnail { fmt=Gif
+                       , img=thm
+                       , sz=size'
+                       , lbs=strictToLazy bs
+                       }
+        
+    strictToLazy = L.pack . BS.unpack
+    
+newSize :: Size -> Size
+newSize (w, h) | w >= h && wMax*h`div`w > wMin = (wMax, wMax*h`div`w)
+               | w >= h && h >= hMin           = (hMin*w`div`h, hMin)
+               | w <  h && hMax*w`div`h > hMin = (hMax*w`div`h, hMax)
+               | w <  h && w >= wMin           = (wMin, wMin*h`div`w)
+               | otherwise = (w, h)
+
+wMax, wMin, hMax, hMin :: Int
+(wMax, wMin) = (60, 20)
+(hMax, hMin) = (60, 20)
diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright (c)2011, Katsutoshi Itoh
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * Neither the name of Katsutoshi Itoh nor the names of other
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/thumbnail.cabal b/thumbnail.cabal
new file mode 100644
--- /dev/null
+++ b/thumbnail.cabal
@@ -0,0 +1,17 @@
+Name:                thumbnail
+Version:             0.1
+Synopsis:            generate thumbnail image
+Description:         generate thumbnail image
+Homepage:            https://github.com/cutsea110/thumbnail
+License:             BSD3
+License-file:        LICENSE
+Author:              Katsutoshi Itoh
+Maintainer:          cutsea110@gmail.com
+Category:            Graphics
+Build-type:          Simple
+Cabal-version:       >=1.2
+Library
+  Exposed-modules:   Graphics.Thumbnail
+  Build-depends:     base >= 4.0 && < 5.0
+                   , gd >= 3000 && < 4000
+                   , bytestring >= 0.9 && < 0.10
