I’m trying to create a thumbnail of an image, for example, this one:

I need the thumbnail to be 500×300. I’ve chosen a very wide image (944×168) for illustration.
The first thing I do in codeigniter is to scale up (or down) the image so that it is as small as possible but covers a 500×300 area. So in this case, I need to scale to 1685×300 since it is wider than it is high. I do this in codeigniter with the following setup:
$config=array(
"image_library"=>"gd2",
"source_image"=>"blah.png",
"maintain_ratio"=>true,
"master_dim"=>"height", /* in this case, with a wide image, this is what I want*/
"height"=>300,
"width"=>1685 /* calculated by (width/height)*300 */
);
Then I perform it as follows:
$this->load->library('image_lib',$config);
$this->image_lib->resize();
But codeigniter gives me this:

which is not what I expect because I have only resized at this stage, not cropped. It is the right resolution though, 1685×300
I expect this, but with a resolution of 1685×300

What am I doing wrong here?
I was calling
$this->image_lib->resize()twice.Thanks for the help