iOS photo reversal analysis and PHP service side processing

Source: Internet
Author: User
Tags zts

Objective:
Because of a friend's PHP small project, and to help solve a small problem, now to summarize the summary.
Also do not know that everyone in the use and development of the process encountered a similar scenario, the iphone uploaded photos, found that the image direction upside down, and even a variety of postures (90, 180, 270 degrees rotation) have, t_t.
  

A related list of PHP and Nginx articles:
nginx Service Configuration---PHP service access
nginx+tomcat cluster configuration (1)---root settings and multi-backend distribution configuration
nginx+tomcat cluster configuration (2)---Separation of static and dynamic resources
nginx+tomcat cluster configuration (3)---Get real client IP
nginx+tomcat cluster configuration (4)--rewrite rules and multi-application root setup Ideas

Problem Root Analysis:
In the process of taking pictures, people may shoot horizontally/vertically, in fact, the rotation of the picture is determined by the angle of the shooting. However, because the mobile phone has a gravity sensor, can be adjusted intelligently, so you take photos, in the browsing, are facing you face.
Android/ios are so, but, Android phone, will be normalized, its orientation forever is 0, while iOS is lazy, its in the picture head, set the orientation information, picture data did not do rotation processing .
So after uploading the image on the iphone, if you don't do any processing, it will appear the beginning of the situation, the picture is reversed.

PHP's Solution:
On this issue, there are a lot of solutions on the Internet, basically talked about the Exif plugin processing method.
This is the official API documentation for EXIF plugins and function interfaces.
Of course, the need for special statement: EXIF only support JPEG, TIFF image format , the author here accidentally dropped the pit, good heartache.

$source _file = "/path/to/xxx.jpeg"; $dest _file = "/path/to/yyy.jpeg"; $data = imagecreatefromstring (file_get_contents ( $source _file)); $exif = Exif_read_data ($source _file);//EXIF header, which contains basic information about the photograph, including shooting time, color, width and height, direction if (!empty ($exif ['      Orientation ']) {switch ($exif [' Orientation ']) {case 8: $data = Imagerotate ($data, 90, 0);    Break      Case 3: $data = Imagerotate ($data, 180, 0);    Break      Case 6: $data = Imagerotate ($data,-90, 0);  Break } imagejpeg ($data, $dest _file);}

This is the final solution, a bit right, but to get to this step, the front needs to do a lot of groundwork, such as PHP's EXIF plugin open.

The EXIF plugin opens:
General PHP Plug-in open, or relatively simple, as long as the php.ini do some simple processing can be.
The most feared is that the plugin itself is not installed, which requires additional work.
This article has PHP 5.3.27, but the EXIF extension does not exist and requires an additional standalone installation.
Refer to the following article "WDCP admin panel installation start EXIF, Bcmath complete step".
1. Download the plugin installation package

wget http://soft.itbulu.com/wdcp/exif.zip./

  2. Unpack the EXIF package and shelve it in the PHP home directory

3. Configure and install

/path/to/bin/phpize# enter the EXIF directory./configure--with-php-config=/path/to/php/bin/php-configmakemake Install

The final generated exif.so, file in/path/to/php/extensions/no-debug-non-zts-xxxxxx/.

4. Configure PHP.ini
Remove the '; ' from the front of the Extension=exif.dll.

; extension=exif.dllextension=/path/to/php/extensions/no-debug-non-zts-xxxxxx/exif.so

Remove EXIF-related options before the '; '.

; exif.encode_unicode = Iso-8859-15;exif.decode_unicode_motorola = Ucs-2be;exif.decode_unicode_intel = UCS-2LE; Exif.encode_jis =;exif.decode_jis_motorola = Jis;exif.decode_jis_intel = JIS

Of course, it is important to note that the expansion module Mbstring.dll needs to be opened at the same time and placed before the Exif module.
Of course you can do the same, but this is a lazy way, the operating system for CentOS

Yum-y Install php-mbstring

Then locate the mbstring.so file

Updatedblocate mbstring.so

Add mbstring configuration in php.ini configuration

Extension=/path/to/mbstring.so

Restart of PHP Service:

Since PHP has abandoned the original php-fpm (start|restart|stop) command mode after the 5.3 release, the restart mode needs to be changed.

KILL-USR2 <PHP-FPM pid>

PID query, you can use the PS command, you can also find the PID file, this is a feasible way.

Results:
Because of the previous to PHP is also half-baked, so went a lot of detours, fortunately, the final configuration of the environment, go to the final solution. The individual is still very fortunate, with the help of the net, standing on the shoulders of giants.

Postscript:
Of course, the actual processing of friends in the project, not so smooth, the middle also encountered a picture format problem, is the beginning of the EXIF only support JPEG and TIFF format problem, because in the front of the page to do some work, resulting in the picture in front of the conversion to PNG format, At the same time discarded the orientation information, so the revised scheme has been unsuccessful, depressed, and even once suspected, the correct plan is corrected, ^_^.

Personal site & Public number:

    The smart house of Little Wood

    Personal Game Folio site (still under construction ...): www.mmxfgame.com

iOS photo reversal analysis and PHP service side processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.