trans = AffineTransform.getScaleInstance(smallest, smallest);
double width = smallest * img.getWidth();
double height = smallest * img.getHeight();
double tx = (width < iconSize ? (0d + iconSize - width) / 2 : 0d);
double ty = (height < iconSize ? (0d + iconSize - height) / 2 : 0d);
trans.concatenate(AffineTransform.getTranslateInstance(tx, ty));
} else {
double tx = (img.getWidth() < iconSize ? (0d + iconSize - img.getWidth()) / 2 : 0d);
double ty = (img.getHeight() < iconSize ? (0d + iconSize - img.getHeight()) / 2 : 0d);
trans = AffineTransform.getTranslateInstance(tx, ty);
}