Luca,
Download the source code package for the core Repository module, open the source and look at MakeThumbnail.aspx.
It does exactly what you want, takes querystring parameters, creates a thumbnail image and streams it back to the browser, and it works from within a regular aspx page or a DotNetNuke module.
If you have any questions, let me know.