i have an image that rendered from data i have on my DB. i need to convert this image, with Mercator Projection method, to distorted image that when i'll wrap a 3d sphere with it it'll looks realistic.

do anyone know what are the formulas i need to use to make the distorted image?

P.S. i'm using PHP with GD.


in which format is your original data?

my data is saved as XML, but we'll do here some optimizations after that so save it compressed with some binary algo.

the rendering process has already done and i already have the rendered image as 2d view but without the distortion that should be in images that under Mercator Projection.

to explain more about my needs, i attached link to album 2 photos i uploaded: '2dBefore.jpg' is an example images that show how it's looks like after the data rendering but before the Mercator Projection distortion, and '2dAfter.jpg' show how the image should be looks like after the Mercator Projection distortion

as i understood, the distortion being worse as much as your going north or south from the equator and i need to know how to do that with code (and not with Gimp as i did now)

I'll also explain you generally about my project: it's a game that each user on it should locate on specific location against a planet (sphere). in the game, there are 2 modes: 1. 2d mode - that show maps on 2d view with the users' data on it. 2. 3d mode - that show a sphere with the users' data on it. it's like takes Google maps and Google earth together on the same application. when a player zoom out/in he'll pass between the modes.

i already mapped the world by longitude and latitude and each user have his own coordinate, the rendering of the data on the 2d maps (using PHP and GD) working fine (I'm consider the world like that: http://www.dsscentral.info/dishtips/world105.gif) but in the 3d map i have some hard-times to understands how i should distort it, as you probably understand from the above.

  • 1
    The current replies all agree that this question needs to be clarified.
    – whuber
    Commented Apr 3, 2011 at 17:47

4 Answers 4


You would never be able to do that with PHP and GD only. You are talking about DB, in which format is your original data? Is it a binary file stored into db? shapefile? other gis format?

Regarding projections, a good job was done on pure images : http://www.flickr.com/photos/sbprzd/sets/72057594138628700/ . But I don't know which libraries/algorithm has been used for that. You can maybe try to ask the author. Here is the mercator projection rendered.

I definitely think you should have a look on gdal for that.


Bearing in mind this is a GIS forum, perhaps the easiest way would be to use GDAL as simo said. I assume that your image isn't georeferenced, so you will need to add ground control points, or GCPs. These map pixel locations to world locations. In GDAL you can do that with gdal_translate:

gdal_translate -gcp 0 0 -180 60 (add more GCPs here) source.png intermediate.png

Then you need to warp the image to a Spherical Mercator projection:

gdalwarp -t_srs EPSG:3785 intermediate.png dest.png

As you're using PHP, this would be done on the server and the results should be cached because warping isn't necessarily a cheap operation.

But I'm just shooting in the dark here, as others have said, give us a workflow and we'll have a better idea of what you want.


You're saying that your image is in Mercator projection now, and you need to wrap that around a sphere? Are you hoping to use PHP to render a static sphere, or are you trying to use PHP to prepare a texture for a sphere that will be rendered in some other 3d graphics program?

Probably the easiest projection to get onto the surface of a sphere is one where the image coordinates correspond directly to latitude and longitude values. http://en.wikipedia.org/wiki/Equirectangular_projection describes the general idea.

Simo is right that PHP + GD probably isn't the way to do this elegantly. You can get it to work, iterating over all the pixels and translating them, but gdalwarp is a much better first for what I think you're describing.

Say more about your problem and it might be easier to point you directly to the right tools.


I think an update in 2015 can be useful.

Try ppmglobe (in NetPBM package):

  • jpegtopnm source.jpg > source.pnm

  • ppmglobe < source.pnm > gores.pnm

  • pnmtojpeg < gores.pnm > gores.jpg

This converts mercator to "12 gores" projection.


Photoshop/Irfanview plugin: http://www.flamingpear.com/flexify.html

Online tool: http://www.winski.net/?page_id=7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.