-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
206 lines (163 loc) · 9.39 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Etiqueta Maker</title>
</head>
<body>
<div class="container ">
<header class="d-flex align-items-center ">
<div class="p p-3 pb-md-4 mx-auto text-center">
<h1 class="display-4 fw-normal">Generador de etiquetado frontal</h1>
<p class="fs-5 text-muted">Forma sencilla de crear una etiqueta y descargarla en <strong> svg</strong>,para dar
cumplimiento a la nueva ley. </p>
<p class="fs-5 text-muted">La propuesta apunta a brindar información a los consumidores sobre los componentes de
los alimentos como azúcares, sodio y grasas saturadas con el objetivo de prevenir "la mala nutrición de la
población".</p>
</div>
</header>
<main>
<form id="formText">
<div class="mb-3">
<label class="form-label" for="arriba">Texto linea arriba</label>
<input type="text" name="arriba" id="arriba" value="linea arriba" class="form-control">
</div>
<div class="mb-3">
<label class="form-label" for="arriba">Texto linea abajo</label>
<input type="text" name="abajo" id="abajo" value="linea abajo" class="form-control">
</div>
<div class="d-grid gap-2 col-6 mx-auto">
<input type="button" value="Crear" id="crear" class="btn btn-primary">
</div>
</form>
<div class="d-flex justify-content-center">
<svg xmlns="http://www.w3.org/2000/svg" width="400px" height="400px" viewBox="0 0 200 200" version="1.1">
<polygon style="fill:#000000;stroke:#000000;stroke-width:5px"
points="136.737609507049,188.692435121084 63.2623904929514,188.692435121084 11.3075648789165,136.737609507049 11.3075648789165,63.2623904929514 63.2623904929513,11.3075648789165 136.737609507049,11.3075648789165 188.692435121084,63.2623904929513 188.692435121084,136.737609507049" />
<polygon style="fill:none;stroke:#ffffff;stroke-width:4px"
points="136.737609507049,188.692435121084 63.2623904929514,188.692435121084 11.3075648789165,136.737609507049 11.3075648789165,63.2623904929514 63.2623904929513,11.3075648789165 136.737609507049,11.3075648789165 188.692435121084,63.2623904929513 188.692435121084,136.737609507049" />
<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" style="font-family: Arial Black, Helvetica, sans-serif;
font-size : 20;
fill : #ffffff;
text-transform: uppercase;
">
<tspan x="50%" y="40%" id="first">linea 1</tspan>
<tspan x="50%" y="55%" id="second">linea 2</tspan>
</text>
</svg>
</div>
<div class="d-grid gap-2 col-6 mx-auto mb-2">
<input type="button" value="Guardar SVG" id="saveSvg" class="btn btn-secondary">
</div>
<div class="d-grid gap-2 col-6 mx-auto ">
<input type="button" value="Guardar PNG" id="savePng" class="btn btn-secondary">
</div>
<script>
let arriba = document.getElementById('arriba');
let abajo = document.getElementById('abajo');
let btncrear = document.getElementById('crear');
let btnPng = document.getElementById('savePng')
let btnSvg = document.getElementById('saveSvg')
let svg = document.querySelector('svg')
document.getElementById('first').textContent = arriba.value;
document.getElementById('second').textContent = abajo.value;
btncrear.addEventListener('click', function (evento) {
evento.preventDefault();
document.getElementById('first').textContent = arriba.value;
document.getElementById('second').textContent = abajo.value;
})
let elBlobSrc = () => {
let data = (new XMLSerializer()).serializeToString(svg)
let svgBlob = new Blob([data], {
type: 'image/svg+xml;charset=utf-8'
})
let url = URL.createObjectURL(svgBlob)
return url
}
let triggerDownloadSvg = (imgURI, fileName) => {
let a = document.createElement('a')
a.setAttribute('download', abajo.value + '.svg')
a.setAttribute('href', imgURI)
a.setAttribute('target', '_blank')
a.click()
}
let triggerDownloadPng = (imgURI, fileName) => {
const img = new Image();
img.addEventListener('load', () => {
const bbox = svg.getBBox();
const canvas = document.createElement('canvas');
canvas.width = bbox.width+150;
canvas.height = bbox.height+150;
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0, canvas.width, canvas.height);
let a = document.createElement('a')
a.setAttribute('download', abajo.value + '.png')
a.setAttribute('href', canvas.toDataURL())
a.setAttribute('target', '_blank')
a.click()
});
img.src = imgURI;
}
btnSvg.addEventListener('click', (evento) => {
evento.preventDefault()
triggerDownloadSvg(elBlobSrc())
})
btnPng.addEventListener('click', (evento) => {
evento.preventDefault()
triggerDownloadPng(elBlobSrc())
})
</script>
<hr class="m-5">
<p>Fuentes de Consulta</p>
<dd>
<dl>
https://www.lagaceta.com.ar/nota/916943/actualidad/diputados-convirtio-ley-etiquetado-frontal-alimentos-en-consiste-norma.html
</dl>
<dl>https://upload.wikimedia.org/wikipedia/commons/6/66/Regular_octagon.svg</dl>
<dl>https://developer.mozilla.org/es/docs/Web/SVG/Element/text#ejemplo</dl>
<dl>https://www.tutorialscampus.com/html5/svg-draw-octagon.htm</dl>
<dl>https://www.w3schools.com/graphics/svg_text.asp</dl>
<dl>https://stackoverflow.com/questions/3975499/convert-svg-to-image-jpeg-png-etc-in-the-browser</dl>
<dl>https://takuti.me/note/javascript-save-svg-as-image/</dl>
</dd>
</main>
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
<div class="col-md-4 d-flex align-items-center">
<span class="text-muted">© 2021</span>
</div>
<ul class="nav col-md-4 justify-content-end list-unstyled d-flex">
<li class="ms-3"><a class="text-muted" href="https://github.com/facundoruiz/etiquetafrontal" target="_blank"
rel="noopener noreferrer" title="github"><svg class="bi" width="24" height="24">
<use xlink:href="#GitHub"></use>
</svg></a></li>
<li class="ms-3"><a class="text-muted" href="https://twitter.com/el_facu" target="_blank"
rel="noopener noreferrer" title="twitter"><svg class="bi" width="24" height="24">
<use xlink:href="#twitter"></use>
</svg></a></li>
<li class="ms-3"><a class="text-muted" href="https://www.linkedin.com/in/facundoruiz/" target="_blank"
rel="noopener noreferrer" title="linkedin"><svg class="bi" width="24" height="24">
<use xlink:href="#linkedin"></use>
</svg></a></li>
</ul>
</footer>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="GitHub" viewBox="0 0 16 16">
<path
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z" />
</symbol>
<symbol id="linkedin" viewBox="0 0 16 16">
<path
d="M0 1.146C0 .513.526 0 1.175 0h13.65C15.474 0 16 .513 16 1.146v13.708c0 .633-.526 1.146-1.175 1.146H1.175C.526 16 0 15.487 0 14.854V1.146zm4.943 12.248V6.169H2.542v7.225h2.401zm-1.2-8.212c.837 0 1.358-.554 1.358-1.248-.015-.709-.52-1.248-1.342-1.248-.822 0-1.359.54-1.359 1.248 0 .694.521 1.248 1.327 1.248h.016zm4.908 8.212V9.359c0-.216.016-.432.08-.586.173-.431.568-.878 1.232-.878.869 0 1.216.662 1.216 1.634v3.865h2.401V9.25c0-2.22-1.184-3.252-2.764-3.252-1.274 0-1.845.7-2.165 1.193v.025h-.016a5.54 5.54 0 0 1 .016-.025V6.169h-2.4c.03.678 0 7.225 0 7.225h2.4z" />
</symbol>
<symbol id="twitter" viewBox="0 0 16 16">
<path
d="M5.026 15c6.038 0 9.341-5.003 9.341-9.334 0-.14 0-.282-.006-.422A6.685 6.685 0 0 0 16 3.542a6.658 6.658 0 0 1-1.889.518 3.301 3.301 0 0 0 1.447-1.817 6.533 6.533 0 0 1-2.087.793A3.286 3.286 0 0 0 7.875 6.03a9.325 9.325 0 0 1-6.767-3.429 3.289 3.289 0 0 0 1.018 4.382A3.323 3.323 0 0 1 .64 6.575v.045a3.288 3.288 0 0 0 2.632 3.218 3.203 3.203 0 0 1-.865.115 3.23 3.23 0 0 1-.614-.057 3.283 3.283 0 0 0 3.067 2.277A6.588 6.588 0 0 1 .78 13.58a6.32 6.32 0 0 1-.78-.045A9.344 9.344 0 0 0 5.026 15z" />
</symbol>
</svg>
</div>
</body>
</html>