Skip to content

Commit

Permalink
Adds a border to the image to help process the QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Oct 13, 2023
1 parent 6f07be6 commit 28616a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion web/src/main/kotlin/org/who/ddccverifier/web/RestController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import org.springframework.web.multipart.MultipartFile
import org.who.ddccverifier.QRDecoder
import org.who.ddccverifier.trust.CompoundRegistry
import org.who.ddccverifier.trust.TrustRegistryFactory
import java.awt.Color
import java.awt.Graphics2D
import java.awt.image.BufferedImage
import java.io.ByteArrayInputStream
import javax.imageio.ImageIO
import kotlin.String
Expand Down Expand Up @@ -52,7 +55,7 @@ class RestController {
}

val binaryBitmap = BinaryBitmap(HybridBinarizer(
BufferedImageLuminanceSource(image)
BufferedImageLuminanceSource(addBordertoImage(image))
))

val qrContents = try {
Expand All @@ -63,4 +66,28 @@ class RestController {

return this.verify(QRContents(qrContents.text))
}

fun addBordertoImage(source: BufferedImage, color: Color = Color.WHITE, borderLeft: Int = 50, borderTop: Int = 50): BufferedImage {
val borderedImageWidth: Int = source.width + borderLeft * 2
val borderedImageHeight: Int = source.height + borderTop * 2
val img = BufferedImage(borderedImageWidth, borderedImageHeight, source.type)
img.createGraphics()
val g = img.graphics as Graphics2D
g.color = color
g.fillRect(0, 0, borderedImageWidth, borderedImageHeight)
g.drawImage(
source,
borderLeft,
borderTop,
source.width + borderLeft,
source.height + borderTop,
0,
0,
source.width,
source.height,
Color.BLACK,
null
)
return img
}
}
4 changes: 2 additions & 2 deletions web/src/main/kotlin/org/who/ddccverifier/web/UIController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class UIController {
return RedirectView("showCredential");
}

var fhir = FhirContext.forCached(FhirVersionEnum.R4)
val fhir = FhirContext.forCached(FhirVersionEnum.R4)
.newJsonParser()
.setPrettyPrint(true);

var json = json.enable(SerializationFeature.INDENT_OUTPUT);
val json = json.enable(SerializationFeature.INDENT_OUTPUT);

redirect.addFlashAttribute("status", result.status)
redirect.addFlashAttribute("qr", result.qr)
Expand Down

0 comments on commit 28616a8

Please sign in to comment.