title: Golang Converting Image magick object to []byte
body: <p>I am using the following code which fetch the object from Amazon s3 and after performing resizing and cropping. I want to store it on s3. But the problem is i am not able convert the <code>mw (Image maigck object)</code> to byte array. Which will be used for storing it on s3. Moreover in current method it uses jpeg.Encode. What if the image in .png or .gif format. How will we convert it to []byte?  </p>
  
  <p>Could you please also tell me how to evenly crop an image just passing the aspect ratio not cropping coordinates. <code>imgStream.Crop((int)originalWidth, ((int)(originalWidth / masterAspectRatio)), Gravity.Center)</code> like we do it in .net. Reason i am asking is there is no method in library which provides this flexibility. </p>
  
  <pre><code>s3Client := s3.New(session.New(), &amp;aws.Config{Region: aws.String(region)})
              params := &amp;s3.GetObjectInput{
              Bucket: aws.String(bucketName),
              Key: aws.String(keyName),
              }
  
          out, err := s3Client.GetObject(params)
  
          if err != nil {
               log.Fatal(err)
          }
  
          img, err := ioutil.ReadAll(out.Body)
          if err != nil {
              log.Fatal(err)
          }      
  
          mw := imagick.NewMagickWand()   
  
          err = mw.ReadImageBlob(img)
          if err != nil {
              log.Fatal(err)
          }
  
          //Perform resizing and cropping on mw object
  
          buf := new(bytes.Buffer)
          err = jpeg.Encode(buf, mw, nil)
          sendmw_s3 := buf.Bytes()
  
           paramsPut := &amp;s3.PutObjectInput{
                          Bucket:         aws.String(masterBucketName),
                          Key:            aws.String(keyName),
                          Body:         bytes.NewReader(sendmw_s3),
                  }
  
          resp, err := s3Client.PutObject(paramsPut)
          if err != nil {
              log.Fatal(err)
          }
  </code></pre>
  
  <p>Error : </p>
  
  <pre><code> cannot use mw (type *imagick.MagickWand) as type image.Image in argument to jpeg.Encode:
      *imagick.MagickWand does not implement image.Image (missing At method)
  </code></pre>