Ticketa
Registered
Привет, работя под framework YII с компонент Image handler и когато качвам , чрез телефон снимка в платформата ми тя се завърта наобратно.
Към момента проблема го решавам по-следния начин:
Но това ми създава проблем. Снимката се прикачва правилно , НО в дясно остава ЧЕРНА ивица/линия/бекграунд.
Което разваля снимката.
Прилагам и цялата ми функция за прикачване на снимката:
Проблема ми е сходен с на този потребител: https://stackoverflow.com/questions/32135931/image-is-rotated-correctly-on-mobile-device-not-on-desktop
http://i.imgur.com/ARwSUuV.png
http://i.imgur.com/00yj7OJ.png
Към момента проблема го решавам по-следния начин:
PHP:
//Read the JPEG image Exif data to get the Orientation value
if (function_exists('exif_read_data')) {
$exif = exif_read_data($file);
$orientation = @$exif['IFD0']['Orientation'];
if (!$orientation) {
$orientation = @$exif['Orientation'];
}
if(!$orientation) return;
$source = @imagecreatefromjpeg($file);
if(!$source) return;
switch ($orientation) {
case 1: // nothing
break;
case 2: // horizontal flip
imageflip($source, IMG_FLIP_HORIZONTAL);
break;
case 3: // 180 rotate left
$modifiedImage = imagerotate($source, 180, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
case 4: // vertical flip
imageflip($source, IMG_FLIP_VERTICAL);
break;
case 5: // vertical flip + 90 rotate right
imageflip($source, IMG_FLIP_VERTICAL);
$modifiedImage = imagerotate($source, -90, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
case 6: // 90 rotate right
$modifiedImage = imagerotate($source, -90, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
case 7: // horizontal flip + 90 rotate right
imageflip($source, IMG_FLIP_HORIZONTAL);
$modifiedImage = imagerotate($source, -90, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
case 8: // 90 rotate left
$modifiedImage = imagerotate($source, 90, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
}
}
//Read the JPEG image Exif data to get the Orientation value
Но това ми създава проблем. Снимката се прикачва правилно , НО в дясно остава ЧЕРНА ивица/линия/бекграунд.
Което разваля снимката.
Прилагам и цялата ми функция за прикачване на снимката:
PHP:
private function loadImage($file)
{
$result = [];
if ($imageInfo = @getimagesize($file)) {
$result['width'] = $imageInfo[0];
$result['height'] = $imageInfo[1];
$result['mimeType'] = $imageInfo['mime'];
switch ($result['format'] = $imageInfo[2]) {
case self::IMG_GIF:
if(file_exists($file)) {
$gd = @imagecreatefromstring(file_get_contents($file));
if ($gd === false) {
throw new Exception ('Invalid image gif format');
} else {
if ($result['image'] = imagecreatefromgif($file)) {
return $result;
} else {
throw new Exception('Invalid image gif format');
}
}
} else {
throw new Exception('Invalid image gif format');
}
break;
case self::IMG_JPEG:
if(file_exists($file)) {
$gd = @imagecreatefromstring(file_get_contents($file));
if ($gd === false) {
throw new Exception ('Invalid image jpeg format');
} else {
//Read the JPEG image Exif data to get the Orientation value
if (function_exists('exif_read_data')) {
$exif = exif_read_data($file);
$orientation = @$exif['IFD0']['Orientation'];
if (!$orientation) {
$orientation = @$exif['Orientation'];
}
if(!$orientation) return;
$source = @imagecreatefromjpeg($file);
if(!$source) return;
switch ($orientation) {
case 1: // nothing
break;
case 2: // horizontal flip
imageflip($source, IMG_FLIP_HORIZONTAL);
break;
case 3: // 180 rotate left
$modifiedImage = imagerotate($source, 180, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
case 4: // vertical flip
imageflip($source, IMG_FLIP_VERTICAL);
break;
case 5: // vertical flip + 90 rotate right
imageflip($source, IMG_FLIP_VERTICAL);
$modifiedImage = imagerotate($source, -90, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
case 6: // 90 rotate right
$modifiedImage = imagerotate($source, -90, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
case 7: // horizontal flip + 90 rotate right
imageflip($source, IMG_FLIP_HORIZONTAL);
$modifiedImage = imagerotate($source, -90, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
case 8: // 90 rotate left
$modifiedImage = imagerotate($source, 90, 0);
imagejpeg($modifiedImage, $file, 90); //save output to file system at full quality
break;
}
}
//Read the JPEG image Exif data to get the Orientation value
if ($result['image'] = @imagecreatefromjpeg($file)) {
return $result;
} else {
throw new Exception('Invalid image jpeg format');
}
}
} else {
throw new Exception('Invalid image jpeg format');
}
break;
case self::IMG_PNG:
if(file_exists($file)) {
$gd = @imagecreatefromstring(file_get_contents($file));
if ($gd === false) {
throw new Exception ('Invalid image png format');
} else {
if ($result['image'] = imagecreatefrompng($file)) {
return $result;
} else {
throw new Exception('Invalid image png format');
}
}
} else {
throw new Exception('Invalid image png format');
}
break;
default:
throw new Exception('Not supported image format');
}
} else {
throw new Exception('Invalid image file');
}
}
Проблема ми е сходен с на този потребител: https://stackoverflow.com/questions/32135931/image-is-rotated-correctly-on-mobile-device-not-on-desktop
http://i.imgur.com/ARwSUuV.png
http://i.imgur.com/00yj7OJ.png