Я пытаюсь решить проблему ориентации при загрузке изображений с мобильных устройств.
Фотографии загружаются, но коррекция поворота не применяется.
Использование класса манипулирования изображениями из Codeigniter.
Заранее благодарю за ваши предложения.
Вот мой код:
public function changeimage() {
$this->load->library('upload');
$sid = $this->session->userdata['user']['id'];
$files = $_FILES;
if (!empty($_FILES['image']['name'])) {
$format = explode('.', $files['image']['name']);
$format = end($format);
$cimagename = md5(uniqid(mt_rand())) . ".$format";
$_FILES['image']['name'] = $cimagename;
$_FILES['image']['type'] = $files['image']['type'];
$_FILES['image']['tmp_name'] = $files['image']['tmp_name'];
$_FILES['image']['error'] = $files['image']['error'];
$_FILES['image']['size'] = $files['image']['size'];
$date = date('Y/m/d H:i:s', time());
$date1 = date('Y/m/d ', strtotime($this->input->post('createdon')));
$this->upload->initialize($this->set_upload_options($sid, $date1));
if (!$this->upload->do_upload("image")) {
$data['error'] = true;
$data['errormsg'] = "Something went wrong";
echo $data['errormsg'];
} else {
$data = array("upload_data" => $this->upload->data());
$image_info = $this->upload->data();
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $files;
$config['new_image'] = $files;
$exif = exif_read_data($config['source_image']);
if ($exif && isset($exif['Orientation'])) {
$ort = $exif['Orientation'];
if ($ort == 6 || $ort == 5)
$config['rotation_angle'] = '270';
if ($ort == 3 || $ort == 4)
$config['rotation_angle'] = '180';
if ($ort == 8 || $ort == 7)
$config['rotation_angle'] = '90';
}
$this->image_lib->initialize($config);
if (!$this->image_lib->rotate()) {
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
$this->load->library("image_lib");
$config['image_library'] = "gd2";
$config['library_path'] = '/login/application/libraries/';
$config['source_image'] = "assets/userimages/" . $image_info['file_name'];
$config['maintain_ratio'] = FALSE;
$config['rotation_angle'] = '';
$sizes = array(array("name" => "thumb", "width" => "200", "height" => "227"));
foreach ($sizes as $size) {
$config['new_image'] = "assets/userimages/" . $size['name'] . "_" . $image_info['file_name'];
$config['width'] = $size['width'];
$config['height'] = $size['height'];
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
}
}
}
}