[F] Vertical images

This commit is contained in:
2025-10-27 00:19:17 +08:00
parent dbc686debf
commit 767bf9c121
@@ -7,6 +7,7 @@ import android.graphics.Typeface
import androidx.core.content.res.ResourcesCompat
import com.ashampoo.kim.Kim
import com.ashampoo.kim.model.MetadataUpdate
import com.ashampoo.kim.model.TiffOrientation
import com.caverock.androidsvg.SVG
import com.caverock.androidsvg.SVGExternalFileResolver
import qrcode.QRCode
@@ -24,12 +25,15 @@ suspend fun genSvg(template: String, imagePath: String): Pair<String, ExifResult
var svg = template
// Read target image's EXIF data
val imageData = Path(imagePath).readBytes()
var imageData = Path(imagePath).readBytes()
val exif = parseExif(imageData) ?: error("No EXIF data found")
println(exif)
val qr = createQRCode("https://p.aza.moe/${exif.urlName}")
val stream = ByteArrayOutputStream().also { qr.writeImage(it) }
// Check EXIF rotation: If it's vertical, rotate the image before embedding
if (exif.w < exif.h) imageData = Kim.update(imageData, MetadataUpdate.Orientation(TiffOrientation.ROTATE_RIGHT))
svg = svg.replace("2025-09-26  14:59", exif.dateTime)
.replace("Nag<tspan x=\"1309.04px 1369.61px 1408.89px 1468.58px 1508.64px \" y=\"4531.84px 4531.84px 4531.84px 4531.84px 4531.84px \">atoro</tspan>, Saitama, Japan", exif.location)
// .replace("""Son<tspan x="4080.43px " y="4377.36px ">y</tspan> IL<tspan x="4189.39px " y="4377.36px ">C</tspan>E-6700 + T<tspan x="4553.27px " y="4377.36px ">a</tspan>mr<tspan x="4679.42px " y="4377.36px ">o</tspan>n 18-300 F3.5-6.3""", exif.cameraInfo)
@@ -62,9 +66,12 @@ fun renderSvgAndroid(context: Context, svg: String): Picture? {
}
fun renderSvgBytes(context: Context, svg: String, exif: ExifResult) = renderSvgAndroid(context, svg)?.run {
this to ByteArrayOutputStream().also {
var img = ByteArrayOutputStream().also {
Bitmap.createBitmap(this).compress(Bitmap.CompressFormat.JPEG, 90, it)
}.toByteArray().let {
Kim.update(it, MetadataUpdate.TakenDate(System.currentTimeMillis()))
}
}.toByteArray()
// If vertical, rotate back
if (exif.w < exif.h) img = Kim.update(img, MetadataUpdate.Orientation(TiffOrientation.ROTATE_LEFT))
this to img
}