You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i had to upgrade my image library package to 4.3.0 because of conflict with other libraries now I'm using image 4.3.0
and now this function from my flutter app has syntax errors after i changed the library version...any help?! :(
tried many things couldnt figure the issue
Future<List> addTextWithBorderAsImage(
String text, {
required Generator generator,
required int linesAfter,
double fontSize = 24.0,
TextAlign align = TextAlign.left,
TextDirection textDirection = TextDirection.ltr,
bool bold = false,
}) async {
// Generate the text as an image
final textImageBytes = await _textToImage(
text,
fontSize: fontSize,
align: align,
textDirection: textDirection,
bold: bold, // Use the parameter value instead of hardcoding true
);
final textImage = img.decodeImage(textImageBytes);
if (textImage == null) {
throw Exception("Failed to decode text image.");
}
// Add padding for the border
final borderPadding = 10;
// Create a new image with extra space for the border
final borderedImage = img.Image(
width: textImage.width + borderPadding * 2,
height: textImage.height + borderPadding * 2,
numChannels: 4,
);
// Fill the background with white
img.fill(borderedImage, img.getColor(255, 255, 255)); // White background
// Draw a black border
img.drawRect(
borderedImage,
x1: 0,
y1: 0,
x2: borderedImage.width - 1,
y2: borderedImage.height - 1,
color: img.getColor(0, 0, 0), // Black border
);
// Paste the text image into the bordered image
img.copyInto(
borderedImage,
textImage,
dstX: borderPadding,
dstY: borderPadding,
);
// Convert the bordered image to raster data for the generator
return generator.imageRaster(
borderedImage,
align: PosAlign.center,
);
I fixed up the code with comments describing the changes.
final textImage = img.decodeImage(textImageBytes);
if (textImage ==null) {
throwException("Failed to decode text image.");
}
// Add padding for the borderfinal borderPadding =10;
// Create a new image with extra space for the borderfinal borderedImage = img.Image(
width: textImage.width + borderPadding *2,
height: textImage.height + borderPadding *2,
numChannels:4,
);
// Fill the background with white// *****************************// int32 colors were removed in favor of more generic Color objects, so getColor was removed.// Images can now support many different types of formats and bit-depths, and it was necessary to move away// from the restrictive uint32 colors.// *****************************
img.fill(borderedImage, color: img.ColorRgb8(255, 255, 255)); // White background// Draw a black border// *****************************// Use of ColorRgb8 instead of getColor.// *****************************
img.drawRect(
borderedImage,
x1:0,
y1:0,
x2: borderedImage.width -1,
y2: borderedImage.height -1,
color: img.ColorRgb8(0, 0, 0), // Black border
);
// Paste the text image into the bordered image// *****************************// copyInto was removed because there previously were multiple functions that did essentially the same thing, and they// were consolidated into the single compositeImage function.// *****************************
img.compositeImage(
borderedImage,
textImage,
dstX: borderPadding,
dstY: borderPadding,
);
i had to upgrade my image library package to 4.3.0 because of conflict with other libraries now I'm using image 4.3.0
and now this function from my flutter app has syntax errors after i changed the library version...any help?! :(
tried many things couldnt figure the issue
Future<List> addTextWithBorderAsImage(
String text, {
required Generator generator,
required int linesAfter,
double fontSize = 24.0,
TextAlign align = TextAlign.left,
TextDirection textDirection = TextDirection.ltr,
bool bold = false,
}) async {
// Generate the text as an image
final textImageBytes = await _textToImage(
text,
fontSize: fontSize,
align: align,
textDirection: textDirection,
bold: bold, // Use the parameter value instead of hardcoding true
);
}
final borderedImage =** img.Image**(
** textImage.width + borderPadding * 2,**
textImage.height + borderPadding * 2,
);
** img.fill(borderedImage, img.getColor(255, 255, 255)); // White background**
** img.drawRect(**
borderedImage,
0, // x1
0, // y1
borderedImage.width - 1, // x2
borderedImage.height - 1, // y2
img.getColor(0, 0, 0), // Black border
);
** img.copyInto(**
***
The text was updated successfully, but these errors were encountered: