IOS: proportional compression code, ios proportional Compression
Compress and enlarge an image according to the desired size, and finally extract the required size. I don't know if it is clear. That's what it means anyway!
+ (UIImage *) compressImageWith :( UIImage *) image width :( float) width height :( float) height {float imageWidth = image. size. width; float imageHeight = image. size. height; float widthScale = imageWidth/width; float heightScale = imageHeight/height; // create a bitmap context // and set it to the currently used context UIGraphicsBeginImageContext (CGSizeMake (width, height); if (widthScale> heightScale) {[image drawInRect: CGRectMake (0, 0, imageWidth/heightScale, height)];} else {[image drawInRect: CGRectMake (0, 0, width, imageHeight/widthScale)];} // create an image UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext (); [newImage retain] from the current context; // make the current context output the stack UIGraphicsEndImageContext (); return newImage ;}
The image will be compressed to 200x200
Proportional compression means that the ratio of length to width remains unchanged.
For example, if the original image is 800*600, and you change the length to 400, then the corresponding width is 300.
I don't understand.
For a 120x90 image, how can the new image generated by the program equal to compression be not distorted?
How do you compress it? Is it possible that PHP is not professional in graph processing to call the GD library function of PHP.
I have installed an imagemagicsoftware, which can use the command line to call the console program convert.exe to compress and convert images. I think it works well.