Using "croppie" on front-end / What do I exactly need to do on back-end to actually crop the image? - node.js

How do I actually crop and compress (resize to snippet size) the image on back-end?
I'm using croppie on front-end: https://foliotek.github.io/Croppie/
I'm completely lost, small guidance would be very helpful.
Thanks!

Why do you want crop your pic on back-end? This operation should have be done in browser. When you use result({ type, size, format, quality, circle }) function, you can get data of cropped pic. If type is base64, you can save the data to file after base64_decode it.

Related

Generate a video from generated images

I currently have an API route in nodeJS generating images from given inputs and then creating and returning a GIF from these images. I'm using gifencoder and canvas to do these operations.
I need to generate a mp4 video instead of a GIF for this route, so I've looked at different solutions, but none suited me:
Converting the GIF to an mp4 with an ffmpeg, seems a little "heavy" and ffmepg need an image path on input to perform this.
Using the image data from canvas to directly feed the videoshow module, less heavy, but it still need images path.
I'd like to not save temporary images for this operation and having a straightforward process like :
"Informations > ImageData > Video".
Do you think it is doable ?

How to force to show image orientation?

I'm using multer node and express to upload a image to my app. But some images shows rotate 90 degrees when it's on the client.
why is this happening?, how can I fix it?
By the way I'm using vue on the client and for the upload process, of course I use formdata
UPDATE
After research and comments from the guys above, its a EXIF problem. Any code ideas to solve this?
The behaviour you are experiencing is probably caused by the Exif Orientation metadata.
There is another question here on Stackoverflow about this problem: JS Client-Side Exif Orientation: Rotate and Mirror JPEG Images
The selected answer points to a project called Javascript-Load-Image as a possible solution, that basically means you will have to take the orientation in consideration when rendering the images to get a consistent behaviour.
Another possible alternative would be to edit/remove the orientation metadata in your backend.
Check the following resource for more information:
JPEG Image Orientation and Exif
This is most likely caused by Exif metadata (just like #Romulo suggested).
Browsers ignore Exif metadata when displaying images and that's why you're getting this behaviour.
To check that this is related to Exif take 4 pictures with different phone orientation (landscape left, landscape right, portrait, upside down). One of them will be shown properly, while the other 3 will be rotated. (Also note that if you're using the front camera, the image will also get mirrored).
Not all camera phones do this, but iOS does it consistently. The reason for this is performance. When rotation the phone the sensor also rotates and the picture taken doesn't take the rotation into consideration.
To properly show the photo, the image needs to be rotated, but if you just change the Exif metadata then you don't need to do it. Of course, any client that shows the image needs to be aware of this information (and iOS Photos and such are aware).
This has nothing to do with multer, but with the images are stored.
The bottom line is that you need to rotate the image to compensate for this.
Take a look over this npm package to adjust your image on the server side.

Using HTML code to detect image size on screen

I'm developing an app that grabs the HTML from a webpage and looks at images, within the HTML, that can be compressed and resized.
I can do the first part no problem in node, using Sharp here:
https://www.npmjs.com/package/sharp
I can, of course, resize the same image here too. I just don't know what dimensions to use. I don't want a tiny image to scale up and so on.
Can I somehow detect the size of the image on screen using the HTML I got to begin with?
Thanks in advance.
EDIT:
Sorry for any confusion. I need to know how big the image is being displayed on the page. So, the image may be 400x400 but the css could limit it to 200x200.
If I have a large image (1000x1000) but it's only being shown on screen at 500x500, I'd know it's a great candidate for resizing.
I'm just not sure how I can resize based on it's css dimensions.
I think in Sharp there's a metadata function that lets you access image metadata, e.g. format, width, height, etc.
Example:
const image = sharp(inputJpg);
image.metadata().then(function(metadata) {
// print image width and height
console.log({
width: metadata.width,
height: metadata.height
});
});
In Sharp library,
You can get dimension from this document:
http://sharp.dimens.io/en/stable/search.html?q=dimension
Hope it will help you.
const sharpImage = sharp('test/test.jpg');
image.metadata().then(function(metadata) {
console.log(metadata);
});

Crop images to ratio in Modx TV

Is there some plugin/way to crop images when they are uploaded in a Modx TV?
I got a slider with a ratio of 1:4. Now when the user uploads a image in another ratio, the image will stretch out.
I want something like Facebook does when you upload a cover image which is to high.
(PS: I want to use it later in Migx)
Like 'okyanet' mentioned you can use phpThumbOf to set the dimensions/ratio when MODx delivers the image.
Another way would be to use the extra 'Image+'. You still need phpThumbOf for this, but the Editor can define the clipping manually in the Manager. And you can define the ratio of the clipping in the TV-Setting for the image.
Use phpThumbOf. The 'zoom-crop' parameter will allow you to preserve the source aspect ratio and then crop it to the dimensions you require.
The image is processed when the page is parsed by MODX, rather than at the time of upload.
There are plenty of articles about how to use this extra, including this one:
http://www.belafontecode.com/image-manipulation-with-phpthumbof-in-modx-revolution/

Byte Array to Image then display in DialogBox C++

as the title says, ive got this packet which contains the whole JPEG image file, so i've put that into a byte array, now how do i convert this to an image and then display it.
I dont need to save it, just display it then once the user enters an answer, delete it.
If you're wondering, its a captcha image. Something like what JDownloader does with captchas.
edit: i meant how can i display images in dialog boxes
You can use the GDI+ Image class to do this, using an IStream of your JPEG in memory as the input, which can be done using ISequentialStream::Read.

Resources