[F] Vertical images
This commit is contained in:
@@ -7,6 +7,7 @@ import android.graphics.Typeface
|
|||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import com.ashampoo.kim.Kim
|
import com.ashampoo.kim.Kim
|
||||||
import com.ashampoo.kim.model.MetadataUpdate
|
import com.ashampoo.kim.model.MetadataUpdate
|
||||||
|
import com.ashampoo.kim.model.TiffOrientation
|
||||||
import com.caverock.androidsvg.SVG
|
import com.caverock.androidsvg.SVG
|
||||||
import com.caverock.androidsvg.SVGExternalFileResolver
|
import com.caverock.androidsvg.SVGExternalFileResolver
|
||||||
import qrcode.QRCode
|
import qrcode.QRCode
|
||||||
@@ -24,12 +25,15 @@ suspend fun genSvg(template: String, imagePath: String): Pair<String, ExifResult
|
|||||||
var svg = template
|
var svg = template
|
||||||
|
|
||||||
// Read target image's EXIF data
|
// 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")
|
val exif = parseExif(imageData) ?: error("No EXIF data found")
|
||||||
println(exif)
|
println(exif)
|
||||||
val qr = createQRCode("https://p.aza.moe/${exif.urlName}")
|
val qr = createQRCode("https://p.aza.moe/${exif.urlName}")
|
||||||
val stream = ByteArrayOutputStream().also { qr.writeImage(it) }
|
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)
|
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("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)
|
// .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 {
|
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)
|
Bitmap.createBitmap(this).compress(Bitmap.CompressFormat.JPEG, 90, it)
|
||||||
}.toByteArray().let {
|
}.toByteArray()
|
||||||
Kim.update(it, MetadataUpdate.TakenDate(System.currentTimeMillis()))
|
|
||||||
}
|
// If vertical, rotate back
|
||||||
|
if (exif.w < exif.h) img = Kim.update(img, MetadataUpdate.Orientation(TiffOrientation.ROTATE_LEFT))
|
||||||
|
|
||||||
|
this to img
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user