I'm not entirely sure what you mean by 'optimize', but perhaps you have an older version of GD, which only supported 8-bit colour in JPEGs? If your version is 2 or newer, you should be able to use GD::Image->trueColor(1); (or there are other ways to do this - consult the POD).