Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- ...

## [3.0.1] - 2025-10-30

### Added

- New method `QrGenerator.writeToImage(String)` that returns a `BufferedImage` for a given payload without touching the file system.

## [3.0.0] - 2025-04-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.aytchell</groupId>
<artifactId>qrgen</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<packaging>jar</packaging>

<name>QR code generator</name>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/github/aytchell/qrgen/QrGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,31 @@ public Path writeToTmpFile(String payload, String tmpFilePrefix)
}
}

/**
* Actually create a QR code with the given configuration and payload
* <p>
* This method takes the configuration collected up to here (by using
* the other methods) and a payload string and creates a {@link BufferedImage}
* containing a QR code.
* <p>
* Note that calling this method does not change the configuration.
* So you can keep the instance and generate more QR codes without
* repeating the configuration steps.
*
* @param payload the string to be encoded into a QR code
* @return a {@link BufferedImage} containing the generated QR code
* @throws QrGenerationException thrown in case the computation of the
* QR code goes wrong.
*/
public BufferedImage writeToImage(String payload)
throws QrGenerationException {
try {
return generateImage(payload);
} catch (WriterException e) {
throw new QrGenerationException("Failed to write QR code to Image", e);
}
}

private void writeQrCodeToFile(Path tmpFile, String payload)
throws WriterException, IOException {
final BufferedImage image = generateImage(payload);
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/github/aytchell/qrgen/QrGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ void tooBigPayloadsFail(SizeAndLevel sizeAndLevel) throws IOException {
}
}

@Test
void generatorCanCreateBufferedImage() throws QrGenerationException {
final BufferedImage image = new QrGenerator().writeToImage("https://github.com/aytchell/qrgen");
assertNotNull(image);
}

void generatePayloadWithLvl(int payloadSize, ErrorCorrectionLevel lvl) throws QrGenerationException, IOException {
final QrGenerator gen = new QrGenerator()
.withErrorCorrection(lvl);
Expand Down