title: Glide load into SimpleTarget<Bitmap> not honoring the specified width and height
body: <p>I'm using Glide to load an image, resize it and save it to a file by means of a <code>SimpleTarget&lt;Bitmap&gt;</code>. These images will be uploaded to Amazon S3, but that's besides the point. I'm resizing the images prior to uploading as to save as much user's bandwidth as possible. For my app needs a 1024 pixel wide image is more than enough, so I'm using the following code to accomplish that:</p>
  
  <pre><code>final String to = getMyImageUrl();
  final Context appCtx = context.getApplicationContext();
  
  Glide.with(appCtx)
          .load(sourceImageUri)
          .asBitmap()
          .into(new SimpleTarget&lt;Bitmap&gt;(1024, 768) {
              @Override
              public void onResourceReady(Bitmap resource, GlideAnimation&lt;? super Bitmap&gt; glideAnimation) {
                  try {
                      FileOutputStream out = new FileOutputStream(to);
                      resource.compress(Bitmap.CompressFormat.JPEG, 70, out);
                      out.flush();
                      out.close();
                      MediaScannerConnection.scanFile(appCtx, new String[]{to}, null, null);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          });
  </code></pre>
  
  <p>It works almost perfectly, but the size of the resulting image is not 1024 pixels wide. Testing it with a source image with dimensions of 4160 x 2340 pixels the dimensions of the resulting saved image is 2080 x 1170 pixels.</p>
  
  <p>I've tried playing with the <code>width</code> and <code>height</code> parameters passed to <code>new SimpleTarget&lt;Bitmap&gt;(350, 350)</code> and with these parameters the resulting image dimensions are 1040 x 585 pixels. </p>
  
  <p>I really don't know what to do to make Glide respect the passed dimensions. In fact I'd like to resize the image proportionally so that the bigger dimension (either width or height) will be restricted to 1024 pixels and the smaller one resized accordingly (I believe I'll have to find a way to get the original image dimensions and then pass the width and height to <code>SimpleTarget</code>, but to do that I need Glide to respect the passed width and height!).</p>
  
  <p>Does anyone have a clue what's going on? I'm using Glide 3.7.0.</p>
  
  <hr>
  
  <p>Since this question itself may be useful for people trying to use Glide to resize and save images I believe it is in everyone's interest to provide my actual "solution" which relies on a new <code>SimpleTarget</code>implementation that automatically saves the resized image:</p>
  
  <pre><code>import android.graphics.Bitmap;
  
  import com.bumptech.glide.request.animation.GlideAnimation;
  import com.bumptech.glide.request.target.SimpleTarget;
  
  import java.io.FileOutputStream;
  import java.io.IOException;
  
  public class FileTarget extends SimpleTarget&lt;Bitmap&gt; {
      public FileTarget(String fileName, int width, int height) {
          this(fileName, width, height, Bitmap.CompressFormat.JPEG, 70);
      }
      public FileTarget(String fileName, int width, int height, Bitmap.CompressFormat format, int quality) {
          super(width, height);
          this.fileName = fileName;
          this.format = format;
          this.quality = quality;
      }
      String fileName;
      Bitmap.CompressFormat format;
      int quality;
      public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
              try {
                  FileOutputStream out = new FileOutputStream(fileName);
                  bitmap.compress(format, quality, out);
                  out.flush();
                  out.close();
                  onFileSaved();
              } catch (IOException e) {
                  e.printStackTrace();
                  onSaveException(e);
              }
      }
      public void onFileSaved() {
          // do nothing, should be overriden (optional)
      }
      public void onSaveException(Exception e) {
          // do nothing, should be overriden (optional)
      }
  
  }
  </code></pre>
  
  <p>Using it is as simple as:</p>
  
  <pre><code>Glide.with(appCtx)
          .load(sourceImageUri)
          .asBitmap()
          .into(new FileTarget(to, 1024, 768) {
              @Override
              public void onFileSaved() {
                  // do anything, or omit this override if you want
              }
          });
  </code></pre>