I have a loto of images organized in a tree of different directories, and I would need to process and convert them with Gulp recursively, saving them in each subdirectory.
Let me clarify with an example
source-dir
source-subdir01
source-subdir02
source-subdir03
The jpg images are in the 3 source-subdir; I would need to process them recursively, and save the new rescaled and converted jpg+webp in these 3 new dir <small*>
target-dir
target-subdir01
small01
target-subdir02
small02
target-subdir03
small03
If this way is not possible, I would like to store them in the 3 dir <target-subdir*>
Actually I built this little script that works with one directory, and I would like to make it recursive so that I can set "source-dir" as source and process all the subdirectories at the same time.
gulp.task('rescale', function () {
return gulp
.src('source/*.{jpg}')
.pipe(
responsive(
{
// Resize in jpg + webp
'*.jpg': [
{
width: 150,
},
{
width: 300,
},
{
width: 150,
format: 'webp',
quality: 70,
},
{
width: 300,
format: 'webp',
quality: 70,
}
]
},
{
// Global configuration for all images
// The output quality for JPEG, WebP and TIFF output formats
quality: 80,
// Use progressive (interlace) scan for JPEG and PNG output
//progressive: true,
// Strip all metadata
withMetadata: false
}
)
)
.pipe(gulp.dest('target'))
})
Kind regards,
Matt
Related
How can I record a video and it will be attached to allure like trace or screenshot?
use: {
actionTimeout: 0,
trace: 'on',
screenshot: 'on',
viewport: {width:1920, height: 1080},
video: 'on',
},
that's what I have in playwright.config.ts and video is only one what is NOT working.
According to the documentation, you have to specify the dir property of recordVideo context option. Otherwise videos are not recorded. Thus, your configuration file should look like this:
use = {
actionTimeout: 0,
trace: 'on',
screenshot: 'on',
viewport: { width: 1920, height: 1080 },
video: 'on',
contextOptions: {
recordVideo: {
dir: './output' // Or wherever you want the videos to be saved.
}
}
}
Also, you can specify the record video directory on page level.
Don't forget to call browserContext.close() at the end of your tests, for the videos to be successfully saved. Personally, I do it in test.afterAll() hook.
EDIT: There is an open issue regarding some config options not working as expected, including the video one. On the first comment, one of the developers states that "Video does not work in this case, that's a known issue.". Maybe you can skip the video option completely - I guess it will still work.
EDIT2: To attach the video recording to Allure reporter, include the following code in test.afterAll() hook:
test.afterAll(async ({ }, testInfo) => {
await context.close() // Required for successful save of video recording.
const path = await page.video().path()
await testInfo.attach('video', {
path,
contentType: 'video/webm',
})
})
for playwright with allure report
After(async function (this: ICustomWorld, { result, pickle }: ITestCaseHookParameter) {
...
await this.page?.close();
await this.context?.close();
...
const buffer = fs.readFileSync(videoPath);
await this.attach(buffer, 'video/webm');
});
video will be attached, it is shown as a link attachment, when click on it - open in the next tab video with scenario run
I'm working on an image cropping tool based on cropper-js (made by fengyuanchen).
After testing with several images, every time i crop the image and resize it to small size (120x180), the result is an image with pixelated effect.
As far as I know, when resizing an image this effect could occurs as you are losing information, however when using other tools like MS Paint pixelation effect is smoother.
Actual Image
Link image
Crop and resized Image
Link image
Crop and resized Image with Paint tool
Link image
Piece of code of cropper
const imageElement = element.get(0);
element.on('load', () => {
const cropper = new Cropper(imageElement, {
responsive: true,
aspectRatio: 2/3,
guides: false,
zoomable: true,
zoomOnTouch: false,
zoomOnWheel: false,
movable: true,
toggleDragModeOnDblclick: false,
scalable: false,
cropBoxResizable: true,
autoCrop: true,
autoCropArea: 1,
minCropBoxHeight: 180,
minCropBoxWidth: 120,
viewMode: 1,
ready() {
scope.registerCropperInstance && scope.registerCropperInstance(cropper);
}
});
});
Piece of code for saving
const { height = 180, width = 120, mimeType = 'image/jpeg', quality = 1, imageSmoothingEnabled = false, imageSmoothingQuality = 'high' } = opts;
const cropperCanvas = cropperInstance.getCroppedCanvas({ height, width, imageSmoothingEnabled, imageSmoothingQuality });
return new Promise(function (resolve) {
cropperCanvas.toBlob(function (imgBlob) {
resolve(imgBlob);
}, mimeType, quality);
});
Is anything we could improve ? Thanks in advance.
I'm using html2pdf that creates pdf from html code. It uses html2canvas and jsPDF. The result is very good but slightly different from the original: the font-size and line-height are a little bit different so that the end of the page is not correct. I really need a copy if the div (that has fixed aspect to be correctly rendered on A4 pages).
Is there a way to influence the fonts in the final rendering? The way I produce pdf now is:
savePdf () {
this.pdfDialog = true
let opt = {
// if set firefox will not be able to print as pdf!...
// margin: 0,
filename: 'cv.pdf',
enableLinks: true,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: {
scale: 8,
useCORS: true,
width: 310,
letterRendering: true,
},
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
}
html2pdf().set(opt).from(document.getElementById('printable-cv')).save()]
},
The solution is to add inline styles to the elements. In my case, working in vuejs I ended up with this code:
<div class="presentazione" v-html="presentation" :style="presentationFont"></div>
I'm using the cordova-plugin-camera to take a picture with these options:
quality: 100,
destinationType: Camera.DestinationType.NATIVE_URI,
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: false,
saveToPhotoAlbum: true,
correctOrientation: true
This is working and I get an URL / Path like this:
assets-library://asset/asset.JPG?id=FBA79210-5E65-4C9B-BF19-9F1169B777C0&ext=JPG
Then, I want to convert this path to a cdvfile:// to display the image in an tag.
window.resolveLocalFileSystemURL(imageURI, function(fileEntry) {
const url = fileEntry.toInternalURL()
})
This is also working and I get:
cdvfile://localhost/assets-library/asset/asset.JPG?id=FBA79210-5E65-4C9B-BF19-9F1169B777C0&ext=JPG
But the image is not rendered. I tried to add <access origin="cdvfile:*" /> in my config.xml but that's not working either. How can i get a valid path / url to display the image?
Best wishes,
Joeri
I had the same problem and managed to solve it with a different approach. After getting the cdvfile url I used Photo Library plugin to get the blob file through the getPhoto method passing the id present in the cdvfile url and with this in hand I got the img source working with the base64data as below:
photoLibrary.getPhoto('FBA79210-5E65-4C9B-BF19-9F1169B777C0').then((blob)=>{
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
var base64data = reader.result;
img.src = base64data;
}
});
UPDATE
You can also use getThumbnail function to improve your page loading depending on the quality, size and quantity of photos you app is supposed to handle.
I'm using Angular UI Grid and I've tried to few ways to add an image (logo) to the top of the PDF document which gets exported.
I've had no luck with the implementations I've tried...
exporterPdfHeader: { text: "My Header", image: "<urlOfImage>" }
exporterPdfHeader: { text: "My Header", backgroundImage: "<urlOfImage>" }
exporterPdfHeader: { text: "My Header", backgroundImage: url("<urlOfImage>") }
Is this even possible to do?
Thanks in advance.
Can you add your image inside a custom html header using headerTemplate: 'header-template.html', in grid-options?
See example ui-grid tutorial
edit
OK, having looked at the source and docs for the export, there is nothing there about passing images in the header.
It does refer you to pdfMake
Images
This is simple. Just use the { image: '...' } node type.
JPEG and PNG formats are supported.
var docDefinition = {
content: [
{ // you'll most often use dataURI images on the browser side // if no width/height/fit is provided, the original size will be used image: 'data:image/jpeg;base64,...encodedContent...' },
{ // if you specify width, image will scale proportionally image: 'data:image/jpeg;base64,...encodedContent...', width: 150 },
{ // if you specify both width and height - image will be stretched image: 'data:image/jpeg;base64,...encodedContent...', width: 150, height: 150 },
{ // you can also fit the image inside a rectangle image: 'data:image/jpeg;base64,...encodedContent...', fit: [100, 100] },
{ // if you reuse the same image in multiple nodes, // you should put it to to images dictionary and reference it by name image: 'mySuperImage' },
{ // under NodeJS (or in case you use virtual file system provided by pdfmake) // you can also pass file names here image: 'myImageDictionary/image1.jpg' } ],
images: {
mySuperImage: 'data:image/jpeg;base64,...content...' } }
end of quote
So it looks like you were close.
Can you try a relative path from the root of your website wrapped in single quotes.
Had to write a custom export function to add page margins.
Plnkr
$scope.export = function() {
var exportColumnHeaders = uiGridExporterService.getColumnHeaders($scope.gridApi.grid, uiGridExporterConstants.ALL);
var exportData = uiGridExporterService.getData($scope.gridApi.grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL, true);
var docDefinition = uiGridExporterService.prepareAsPdf($scope.gridApi.grid, exportColumnHeaders, exportData);
docDefinition.pageMargins = [40, 80, 40, 60];
if (uiGridExporterService.isIE() || navigator.appVersion.indexOf("Edge") !== -1) {
uiGridExporterService.downloadPDF($scope.gridOptions.exporterPdfFilename, docDefinition);
} else {
pdfMake.createPdf(docDefinition).open();
}
}
Image has to be provided as base 64 encoded, unless using Node.js (as per pdfmake library).
Otherwise, you may need to use a JavaScript function to download and convert an image to base 64.
References:
https://stackoverflow.com/a/37058202/2808230
pdfExport function in http://ui-grid.info/release/ui-grid.js
Found this as I was writing up this answer: Angular UI Grid - Exporting an image to a pdf