php imagecropauto()不工作

I've written some code that copies a chunk of a big image to a new smaller image and saves it to the server. That all works just fine

However, I would like it to trim off any white background around the text and this is the part that doesn't work

Here is my code

$sourceImage = imagecreatefromjpeg($image); 
$tempImg = imagecreatetruecolor($data[2],$data[3]);
imagecopy($tempImg,$sourceImage, 0, 0, $data[0], $data[1], $data[2], $data[3]);
imagejpeg($tempImg,$destImage,90);
imagedestroy($tempImg);
chmod($destImage,0775);
// these next two lines don't work
$original_img = imagecreatefromjpeg($destImage);
$cropped_destImage = imagecropauto($original_img , IMG_CROP_THRESHOLD, 2, 16777215);

Can anyone see what I'm doing wrong here ?

Thanks

I have looked for you and this is what i found: PHP GD Text with Transparency/Alpha background

This person had a similar problem. It could be worthwhile to read this topic because it has useful pieces of codes to deal with text that already has a background in it.

Found it!!

I hadn't realized I needed to turn the resource back into a jpeg :

$original_img = imagecreatefromjpeg($destImage);
$cropped_destImage = imagecropauto($original_img , IMG_CROP_THRESHOLD, 5, 16777215);
imagejpeg($cropped_destImage,$destImage,90);