This is not possible (at least with PHP / GD, not sure about ImageMagik), sorry.
However, you can try to simulate it, let's say you want to create a 400x300 image of 25 dpi , here is the math:
WIDTH
72 -------- 400 25 -------- w = (25 * 400) / 72 (=) w ~= 139 pixels
HEIGHT
72 -------- 300 25 -------- h = (25 * 300) / 72 (=) h ~= 104 pixels
You create a new image 139x104 72 dpi , work with it and after you make its size up to 400x300 pixels.
source share