Fix portrait image metadata when uploading without media optimization (#6362)

* fix(media): preserve image orientation metadata without optimization

* style: linting
This commit is contained in:
Gianluca Iavicoli 2026-04-08 11:01:54 +02:00 committed by GitHub
parent d38f483cd1
commit 523ede744a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 67 additions and 12 deletions

View file

@ -12,6 +12,7 @@ import android.content.Context
import android.net.Uri
import android.os.Build
import androidx.core.net.toUri
import androidx.exifinterface.media.ExifInterface
import androidx.test.platform.app.InstrumentationRegistry
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.androidutils.file.TemporaryUriDeleter
@ -42,6 +43,30 @@ import kotlin.time.Duration
@RunWith(RobolectricTestRunner::class)
class AndroidMediaPreProcessorTest {
@Test
fun `orientedImageDimensions swaps width and height for 90 degree exif orientation`() {
val (width, height) = orientedImageDimensions(
rawWidth = 4032,
rawHeight = 2268,
orientation = ExifInterface.ORIENTATION_ROTATE_90,
)
assertThat(width).isEqualTo(2268)
assertThat(height).isEqualTo(4032)
}
@Test
fun `orientedImageDimensions keeps width and height for upright exif orientation`() {
val (width, height) = orientedImageDimensions(
rawWidth = 4032,
rawHeight = 2268,
orientation = ExifInterface.ORIENTATION_NORMAL,
)
assertThat(width).isEqualTo(4032)
assertThat(height).isEqualTo(2268)
}
private suspend fun TestScope.process(
asset: Asset,
mediaOptimizationConfig: MediaOptimizationConfig,