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