Closed Anjan-99 closed 2 months ago
this function working proper in my windows laptop but when I upload it to ec2 this below line is not working or giving any error
ticket .composite([ticketIdBuffer, customerNameBuffer, barcodeBuffer]) .toFile(outputFilePath);
// full function const createTicket = async (user_id, name, orderid, event_id, barcodePath) => { // const eventId = event_id.replace(/[^a-zA-Z0-9]/g, ""); const customerName = name; const orderId = orderid; console.log("customerName", user_id, name, orderid, event_id, barcodePath);
const event = await Event.findOne({ event_id });
const passtemplate = event.pass_template; const barcode = await Jimp.read(barcodePath); barcode.resize(196 2, 236 2); console.log("passtemplate", passtemplate); console.log("barcode", barcode);
const nameTop = event.name_top; const nameLeft = event.name_left; const nameColor = event.name_color; const nameSize = event.name_size; const barcodeTop = event.barcode_top; const barcodeLeft = event.barcode_left; const ticketTop = event.ticket_top; const ticketLeft = event.ticket_left; const ticketColor = event.ticket_color; const ticketSize = event.ticket_size;
const ticket = sharp(passtemplate);
const ticketIdSvg = await generateSvg1( orderId, ticketSize, ticketColor, "font/OpenSans-ExtraBold.ttf" );
const customerNameSvg = await generateSvg1( customerName, nameSize, nameColor, "font/OpenSans-ExtraBold.ttf" );
const barcodeBuffer = { input: Buffer.from(await barcode.getBufferAsync(Jimp.MIME_PNG)), left: barcodeLeft, top: barcodeTop, };
const ticketIdBuffer = { input: Buffer.from(ticketIdSvg), left: ticketLeft, top: ticketTop, };
const customerNameBuffer = { input: Buffer.from(customerNameSvg), left: nameLeft, top: nameTop, };
// if pass already exists, delete it first before saving new one if (fs.existsSync(media/userpass/pass_${user_id}.png)) { fs.unlinkSync(media/userpass/pass_${user_id}.png); }
media/userpass/pass_${user_id}.png
const outputFilePath = path.join("media/userpass", pass_${user_id}.png); console.log("outputFilePath", outputFilePath);
pass_${user_id}.png
const pass = await ticket .composite([ticketIdBuffer, customerNameBuffer, barcodeBuffer]) .toFile(outputFilePath);
console.log("ticket generated",pass); return pass_${user_id}.png; };
this function working proper in my windows laptop but when I upload it to ec2 this below line is not working or giving any error
ticket .composite([ticketIdBuffer, customerNameBuffer, barcodeBuffer]) .toFile(outputFilePath);
// full function const createTicket = async (user_id, name, orderid, event_id, barcodePath) => { // const eventId = event_id.replace(/[^a-zA-Z0-9]/g, ""); const customerName = name; const orderId = orderid; console.log("customerName", user_id, name, orderid, event_id, barcodePath);
const event = await Event.findOne({ event_id });
const passtemplate = event.pass_template; const barcode = await Jimp.read(barcodePath); barcode.resize(196 2, 236 2); console.log("passtemplate", passtemplate); console.log("barcode", barcode);
const nameTop = event.name_top; const nameLeft = event.name_left; const nameColor = event.name_color; const nameSize = event.name_size; const barcodeTop = event.barcode_top; const barcodeLeft = event.barcode_left; const ticketTop = event.ticket_top; const ticketLeft = event.ticket_left; const ticketColor = event.ticket_color; const ticketSize = event.ticket_size;
const ticket = sharp(passtemplate);
const ticketIdSvg = await generateSvg1( orderId, ticketSize, ticketColor, "font/OpenSans-ExtraBold.ttf" );
const customerNameSvg = await generateSvg1( customerName, nameSize, nameColor, "font/OpenSans-ExtraBold.ttf" );
const barcodeBuffer = { input: Buffer.from(await barcode.getBufferAsync(Jimp.MIME_PNG)), left: barcodeLeft, top: barcodeTop, };
const ticketIdBuffer = { input: Buffer.from(ticketIdSvg), left: ticketLeft, top: ticketTop, };
const customerNameBuffer = { input: Buffer.from(customerNameSvg), left: nameLeft, top: nameTop, };
// if pass already exists, delete it first before saving new one if (fs.existsSync(
media/userpass/pass_${user_id}.png
)) { fs.unlinkSync(media/userpass/pass_${user_id}.png
); }const outputFilePath = path.join("media/userpass",
pass_${user_id}.png
); console.log("outputFilePath", outputFilePath);const pass = await ticket .composite([ticketIdBuffer, customerNameBuffer, barcodeBuffer]) .toFile(outputFilePath);
console.log("ticket generated",pass); return
pass_${user_id}.png
; };