Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add white margin to QR code image #938

Merged
merged 2 commits into from
Feb 9, 2024
Merged
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
60 changes: 35 additions & 25 deletions src/components/collect-qr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,44 @@ except according to the terms contained in the LICENSE file.
</template>
<!-- eslint-enable vue/no-v-html -->

<script>
<script setup>
import { computed } from 'vue';
import qrcode from 'qrcode-generator';
import pako from 'pako/lib/deflate';

export default {
name: 'CollectQr',
props: {
settings: {
type: Object,
required: true
},
errorCorrectionLevel: {
type: String,
required: true
},
cellSize: {
type: Number,
required: true
}
defineOptions({
name: 'CollectQr'
});

const props = defineProps({
settings: {
type: Object,
required: true
},
errorCorrectionLevel: {
type: String,
required: true
},
computed: {
imgHtml() {
const code = qrcode(0, this.errorCorrectionLevel);
const json = JSON.stringify(this.settings);
code.addData(btoa(pako.deflate(json, { to: 'string' })));
code.make();
return code.createImgTag(this.cellSize, 0);
}
cellSize: {
type: Number,
required: true
}
};
});

const imgHtml = computed(() => {
const code = qrcode(0, props.errorCorrectionLevel);
const json = JSON.stringify(props.settings);
code.addData(btoa(pako.deflate(json, { to: 'string' })));
code.make();
return code.createImgTag(props.cellSize, 15);
});

</script>

<style lang="scss">

.collect-qr img {
margin: -15px;
}

</style>
2 changes: 1 addition & 1 deletion test/components/collect-qr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ describe('CollectQr', () => {
10
);

width2.should.equal(2 * width1);
width2.should.equal(2 * (width1 - 15)); // remove negative padding
});
});