- //PDFLIB_API int PDFLIB_CALL
- //PDF_load_image(i->pPDF *p, const char *imagetype, const char *filename, int len, const char *optlist);
+ double l1 = sqrt(matrix->m00*matrix->m00+matrix->m01*matrix->m01)*img->width;
+ double l2 = sqrt(matrix->m10*matrix->m10+matrix->m11*matrix->m11)*img->height;
+ double r = atan2(matrix->m01, matrix->m00);
+
+ /* fit_image needs the lower left corner of the image */
+ double x = matrix->tx + matrix->m10*img->height;
+ double y = matrix->ty + matrix->m11*img->height;
+
+ char*tempfile = mktempname(0);
+ char options[80];
+ sprintf(options, "boxsize {%f %f} fitmethod meet rotate %f", l1, l2, r*180/M_PI);
+ gfximage_save_jpeg(img, tempfile, 99);
+ int imgid = PDF_load_image(i->p, "jpeg", tempfile, 0, "");
+ PDF_fit_image(i->p, imgid, x, y, options);