Fix iOS picture orientation after upload PHP -


is there way rotate picture php only if not correctly positioned after uploaded ios?

some pictures rotated 90 degrees while others upload correctly.

the image rotating because saving image in jpeg, if save image in png orientation not change. here code fix orientation issue.

- (uiimage *)fixrotation:(uiimage *)image{         if (image.imageorientation == uiimageorientationup) return image;     cgaffinetransform transform = cgaffinetransformidentity;      switch (image.imageorientation) {         case uiimageorientationdown:         case uiimageorientationdownmirrored:             transform = cgaffinetransformtranslate(transform, image.size.width, image.size.height);             transform = cgaffinetransformrotate(transform, m_pi);             break;          case uiimageorientationleft:         case uiimageorientationleftmirrored:             transform = cgaffinetransformtranslate(transform, image.size.width, 0);             transform = cgaffinetransformrotate(transform, m_pi_2);             break;          case uiimageorientationright:         case uiimageorientationrightmirrored:             transform = cgaffinetransformtranslate(transform, 0, image.size.height);             transform = cgaffinetransformrotate(transform, -m_pi_2);             break;         case uiimageorientationup:         case uiimageorientationupmirrored:             break;     }      switch (image.imageorientation) {         case uiimageorientationupmirrored:         case uiimageorientationdownmirrored:             transform = cgaffinetransformtranslate(transform, image.size.width, 0);             transform = cgaffinetransformscale(transform, -1, 1);             break;          case uiimageorientationleftmirrored:         case uiimageorientationrightmirrored:             transform = cgaffinetransformtranslate(transform, image.size.height, 0);             transform = cgaffinetransformscale(transform, -1, 1);             break;         case uiimageorientationup:         case uiimageorientationdown:         case uiimageorientationleft:         case uiimageorientationright:             break;     }      // draw underlying cgimage new context, applying transform     // calculated above.     cgcontextref ctx = cgbitmapcontextcreate(null, image.size.width, image.size.height,                                              cgimagegetbitspercomponent(image.cgimage), 0,                                              cgimagegetcolorspace(image.cgimage),                                              cgimagegetbitmapinfo(image.cgimage));     cgcontextconcatctm(ctx, transform);     switch (image.imageorientation) {         case uiimageorientationleft:         case uiimageorientationleftmirrored:         case uiimageorientationright:         case uiimageorientationrightmirrored:             // grr...             cgcontextdrawimage(ctx, cgrectmake(0,0,image.size.height,image.size.width), image.cgimage);             break;          default:             cgcontextdrawimage(ctx, cgrectmake(0,0,image.size.width,image.size.height), image.cgimage);             break;     }      // , create new uiimage drawing context     cgimageref cgimg = cgbitmapcontextcreateimage(ctx);     uiimage *img = [uiimage imagewithcgimage:cgimg];     cgcontextrelease(ctx);     cgimagerelease(cgimg);     return img; } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -