BP_Media_Rotation::fix_rotation( $source )
Fix rotation of mobile uploaded images
Description
Parameters
- $source
-
(Required)
Return
(bool)
Source
File: bp-media/classes/class-bp-media-rotation.php
function fix_rotation( $source ) {
if ( ! file_exists( $source ) ) {
return false;
}
$exif = null;
$ort = 0;
if ( function_exists( 'exif_read_data' ) ) {
$exif = @exif_read_data( $source );
$ort = isset( $exif['Orientation'] ) ? $exif['Orientation'] : 0;
}
if ( $ort > 1 ) {
$destination = $source;
$size = getimagesize( $source );
$width = $size[0];
$height = $size[1];
$sourceImage = imagecreatefromjpeg( $source );
$destinationImage = imagecreatetruecolor( $width, $height );
//Specifies the color of the uncovered zone after the rotation
$bgd_color = imagecolorallocatealpha( $destinationImage, 0, 0, 0, 127 );
imagecopyresampled( $destinationImage, $sourceImage, 0, 0, 0, 0, $width, $height, $width, $height );
switch ( $ort ) {
case 2:
$this->flip_image( $dimg );
break;
case 3:
$destinationImage = imagerotate( $destinationImage, 180, $bgd_color );
break;
case 4:
$this->flip_image( $dimg );
break;
case 5:
$this->flip_image( $destinationImage );
$destinationImage = imagerotate( $destinationImage, - 90, $bgd_color );
break;
case 6:
$destinationImage = imagerotate( $destinationImage, - 90, $bgd_color );
break;
case 7:
$this->flip_image( $destinationImage );
$destinationImage = imagerotate( $destinationImage, - 90, $bgd_color );
break;
case 8:
$destinationImage = imagerotate( $destinationImage, 90, $bgd_color );
break;
}
return imagejpeg( $destinationImage, $destination, 100 );
}
}
Changelog
| Version | Description |
|---|---|
| BuddyBoss 1.1.1 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.