@Override
  public boolean encode(
      @NonNull Resource<GifDrawable> resource, @NonNull File file, @NonNull Options options) {
    GifDrawable drawable = resource.get();
    Transformation<Bitmap> transformation = drawable.getFrameTransformation();
    boolean isTransformed = !(transformation instanceof UnitTransformation);
    if (isTransformed && options.get(ENCODE_TRANSFORMATION)) {
      return encodeTransformedToFile(drawable, file);
    } else {
      return writeDataDirect(drawable.getBuffer(), file);
    }
  }
@Test
  public void testWritesTransformedBitmaps() {
    final Bitmap frame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    when(decoder.getFrameCount()).thenReturn(1);
    when(decoder.getNextFrame()).thenReturn(frame);

    when(gifEncoder.start(any(OutputStream.class))).thenReturn(true);

    int expectedWidth = 123;
    int expectedHeight = 456;
    when(gifDrawable.getIntrinsicWidth()).thenReturn(expectedWidth);
    when(gifDrawable.getIntrinsicHeight()).thenReturn(expectedHeight);

    Bitmap transformedFrame = Bitmap.createBitmap(200, 200, Bitmap.Config.RGB_565);
    when(transformedResource.get()).thenReturn(transformedFrame);
    when(frameTransformation.transform(
            anyContext(), eq(frameResource), eq(expectedWidth), eq(expectedHeight)))
        .thenReturn(transformedResource);
    when(gifDrawable.getFrameTransformation()).thenReturn(frameTransformation);

    encoder.encode(resource, file, options);

    verify(gifEncoder).addFrame(eq(transformedFrame));
  }