[Editor's note: fixed according to the note of roberto at ilpiola.it]
I could not find any information on changing the DPI information on a JPG file using the GD lib. Since changing this does not resize or scale the actual image, it is only a header-setting.
The following snipplet will save your $image to $file and set the DPI to 150.
<?php
imagejpeg($image, $file, 75);
$dpi_x = 150;
$dpi_y = 150;
$size = filesize($file);
$image = file_get_contents($file);
$image[13] = chr(1);
$image[14] = chr(floor($dpi_x/256));
$image[15] = chr( $dpi_x%256);
$image[16] = chr(floor($dpi_y/256));
$image[17] = chr( $dpi_y%256);
$f = fopen($file, 'w');
fwrite($f, $msg, $size);
fclose($f);
?>
P.s. not fully tested (yet) but it works for my images ...