[F] Fix registration
This commit is contained in:
@@ -4,6 +4,7 @@ package aza.instant
|
||||
|
||||
import com.ashampoo.kim.Kim
|
||||
import com.ashampoo.kim.common.convertToPhotoMetadata
|
||||
import com.ashampoo.kim.format.ImageMetadata
|
||||
import kotlinx.serialization.InternalSerializationApi
|
||||
import java.security.MessageDigest
|
||||
import java.time.LocalDateTime
|
||||
@@ -20,7 +21,7 @@ fun formatExposureTime(t: Double): String {
|
||||
else "%.0fs".format(t)
|
||||
}
|
||||
|
||||
data class ExifResult(val shutterInfo: String, val cameraInfo: String, val dateTime: String, val location: String, val urlName: String, val w: Int, val h: Int) {
|
||||
data class ExifResult(val shutterInfo: String, val cameraInfo: String, val dateTime: String, val location: String, val urlName: String, val w: Int, val h: Int, val raw: ImageMetadata) {
|
||||
override fun toString(): String {
|
||||
return "Date/Time: $dateTime\nLocation: $location\nCamera Info: $cameraInfo\nShutter Info: $shutterInfo\nURL Name: $urlName"
|
||||
}
|
||||
@@ -61,6 +62,7 @@ suspend fun parseExif(data: ByteArray): ExifResult? {
|
||||
},
|
||||
|
||||
w = d.widthPx!!,
|
||||
h = d.heightPx!!
|
||||
h = d.heightPx!!,
|
||||
raw = exif
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Picture
|
||||
import android.media.MediaScannerConnection
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
@@ -103,8 +104,9 @@ fun FileListerScreen(modifier: Modifier = Modifier) {
|
||||
coroutineScope.launch {
|
||||
feedbackText = "Rendering..."
|
||||
val imageDir = File("/storage/emulated/0/DCIM/CA_IMAGES/")
|
||||
val outDir = File("/storage/emulated/0/DCIM/CA_IMAGES_OUT/")
|
||||
val latestImg = imageDir.listFiles()
|
||||
?.filter { !it.name.contains("-framed-") }
|
||||
?.filter { !it.name.contains("-framed") }
|
||||
?.maxByOrNull { it.lastModified() }
|
||||
if (latestImg == null) {
|
||||
feedbackText = "No images found in CA_IMAGES"
|
||||
@@ -114,13 +116,15 @@ fun FileListerScreen(modifier: Modifier = Modifier) {
|
||||
val templateStream = context.resources.openRawResource(R.raw.postcard4)
|
||||
val template = BufferedReader(InputStreamReader(templateStream)).readText()
|
||||
val (svg, exif) = genSvg(template, latestImg.absolutePath)
|
||||
picture = renderSvgAndroid(context, svg)
|
||||
val (pic, bytes) = renderSvgBytes(context, svg, exif) ?: return@launch
|
||||
picture = pic
|
||||
|
||||
// Save picture to file
|
||||
val out = File(latestImg.parent, "${latestImg.nameWithoutExtension}-framed-${System.currentTimeMillis()}.jpg")
|
||||
out.outputStream().use { outputStream ->
|
||||
Bitmap.createBitmap(picture!!).compress(Bitmap.CompressFormat.JPEG, 90, outputStream)
|
||||
}
|
||||
outDir.mkdirs()
|
||||
val out = File(outDir, "${latestImg.nameWithoutExtension}-framed.jpg")
|
||||
.apply { writeBytes(bytes) }
|
||||
|
||||
MediaScannerConnection.scanFile(context, arrayOf(out.absolutePath), null, null)
|
||||
|
||||
feedbackText = "Rendered ${latestImg.name}, now uploading..."
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package aza.instant
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Picture
|
||||
import android.graphics.Typeface
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import com.ashampoo.kim.Kim
|
||||
import com.ashampoo.kim.model.MetadataUpdate
|
||||
import com.caverock.androidsvg.SVG
|
||||
import com.caverock.androidsvg.SVGExternalFileResolver
|
||||
import qrcode.QRCode
|
||||
@@ -25,8 +28,7 @@ suspend fun genSvg(template: String, imagePath: String): Pair<String, ExifResult
|
||||
val exif = parseExif(imageData) ?: error("No EXIF data found")
|
||||
println(exif)
|
||||
val qr = createQRCode("https://p.aza.moe/${exif.urlName}")
|
||||
val stream = ByteArrayOutputStream()
|
||||
qr.writeImage(stream)
|
||||
val stream = ByteArrayOutputStream().also { qr.writeImage(it) }
|
||||
|
||||
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)
|
||||
@@ -58,3 +60,11 @@ fun renderSvgAndroid(context: Context, svg: String): Picture? {
|
||||
SVG.registerExternalFileResolver(FontResolver(context))
|
||||
return SVG.getFromString(svg).renderToPicture(7133 / 2, 4904 / 2)
|
||||
}
|
||||
|
||||
fun renderSvgBytes(context: Context, svg: String, exif: ExifResult) = renderSvgAndroid(context, svg)?.run {
|
||||
this to ByteArrayOutputStream().also {
|
||||
Bitmap.createBitmap(this).compress(Bitmap.CompressFormat.JPEG, 90, it)
|
||||
}.toByteArray().let {
|
||||
Kim.update(it, MetadataUpdate.TakenDate(System.currentTimeMillis()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user