Questions tagged [image-resizing]

Image resizing is the downscaling or upscaling of an image. Dozens of algorithms exist, all with performance vs. quality tradeoffs.

Image resizing (also called image scaling) is the downsampling or up-sampling of an image using an interpolation algorithm. Common downscaling algorithms are Lanczos, Bicubic Sharper, Bicubic Smoother, Fant, Bicubic, Bilinear, and NearestNeighbor (listed in order of average result quality). Fractal algorithms often produce better results for upscaling photos, while there are many algorithms optimized for upscaling pixel art.

Due to algorithmic complexity, most developers use library implementations of these algorithms.

FreeImage

Offers CatmullRom, Lanczos3, bspline, box, bicubic, and bilinear filters. FreeImage focuses on implementation simplicity, and doesn't use hardware accelerations or SIMD extensions, so these speeds may not be acceptable for real-time display of images.

Windows GDI+

While loathed by many, GDI+ does include an excellent 2-pass Bicubic filter. It offers: 2-pass Bicubic, 1-pass bicubic, bilinear, and nearest neighbor. Those using it should be aware that it may add rings to images unless WrapMode is set to TileXY, as otherwise the algorithm samples data from outside the image bounds.

WIC (Windows Imaging Components)

The IWICBitmapScaler class offers Fant, 1-pass bicubic, bilinear, and nearest neighbor. Implementations are optimized for performance, and can be 2-4x faster than their GDI counterparts, although there isn't currently a 2-pass bicubic filter such as offered by GDI+

2188 questions
10
votes
1 answer

PHP GD resizing transparent image giving black border

I am trying to downsize some transparents images in PHP with GD, and whenever I do, there is a weird black-ish border that is added around it. Before After Code
Alex Turpin
  • 46,743
  • 23
  • 113
  • 145
10
votes
7 answers

error: (-215) ssize.width > 0 && ssize.height > 0 in function resize

I am building an image processing classifier. This line is giving me an error: input_img_resize=cv2.resize(input_img,(128,128)) The error: ('error: /io/opencv/modules/imgproc/src/imgwarp.cpp:3483: error: (-215) ssize.width > 0 && ssize.height > 0 in…
Dexter
  • 630
  • 1
  • 11
  • 24
10
votes
1 answer

Resize JPEG image in filesystem

Is there a way to resize a JPEG image file (from filesystem to filesystem) without removing meta data (just like ImageMagicks convert in.jpg -resize 50% out.jpg)? The only way I found to resize .jpg files I found is BitmapFactory.decodeStream and…
Simon Warta
  • 10,850
  • 5
  • 40
  • 78
10
votes
5 answers

How to resize an image in pure HTML/CSS while keeping its proportions?

How can I resize an image using HTML/CSS only (i.e no server code) while keeping its proportions and have a crop effect. Details: I wish to resize it to a specified width, keep the proportions and if the height is bigger than a specified value to…
kmunky
  • 15,383
  • 17
  • 53
  • 64
10
votes
3 answers

Crop image to a square according to the size of a UIView/CGRect

I have an implementation of AVCaptureSession and my goal is for the user to take a photo and only save the part of the image within the red square border, as shown below: AVCaptureSession's previewLayer (the camera) spans from (0,0) (top left) to…
swiftcode
  • 3,039
  • 9
  • 39
  • 64
10
votes
1 answer

Qt: How do I resize an image and maintain its proportions?

This Qt example shows how to resize an image contained in a dialog, so that when the dialog is resized, the image stretches accordingly. How can I resize an image in the same way, without distorting it / keeping its proportions the same? Of course…
Pietro
  • 12,086
  • 26
  • 100
  • 193
10
votes
4 answers

How to set maximum height for $img but keep proportions

How to set maximum height or width for: $img_attributes= ' height=100 width=100 '. 'alt="'.$product['product_name'].'"';
Chris
  • 1,919
  • 6
  • 34
  • 60
10
votes
1 answer

(Qt C++) Resize pixmap and KEEP pixelation?

In my project I have a QLabel that I change the pixmap frequently like this: ui->frameLabel->setPixmap(slot_pic[blockId[currentSlot]][damageId[currentSlot]]); slot_pic is simply a 2d map. So you can look at it clearer like…
mrg95
  • 2,371
  • 11
  • 46
  • 89
10
votes
2 answers

Shrink image size to fit table cell, which works in all browsers?

I have a table which has images in its cells. I want these images to shrink automatically when the window width is reduced. But they should not expand beyond their native size when there's extra space around. I have a solution for this which works…
Ahmad
  • 12,886
  • 30
  • 93
  • 146
10
votes
3 answers

Resize (downsize) YUV420sp image

I am trying to resize (scale down) an image which comes in YUV420sp format. Is it possible to do such image resizing without converting it into RGB, so directly manipulating the YUV420sp pixel array? Where can I find such algorithm? Thanks
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
10
votes
5 answers

How to resize an image in C# to a certain hard-disk size?

How to resize an image an image in C# to a certain hard-disk size, like 2MiB? Is there a better way than trial and error (even if it's approximate, of course). Any particular keywords to search for when trying to find the solution on the web?
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
9
votes
1 answer

Resizing image from input file with Jimp

I want to resize the image which I get through input file. I found that jimp seems to be a good option. The problem I have is that I don't know how to use it on the file. I tried to use this approach: Jimp.read(lenna.buffer) .then(image => { …
9
votes
3 answers

Can one large size favicon serve all devices and browsers?

All discussion about favicons recommend creating favicons of different sizes to target different clients. See this answer for example: Does a favicon have to be 32x32 or 16x16? My question: Is it really necessary to generate favicons with so many…
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
9
votes
1 answer

magick image resize

I am using magick library in R. I am using the following command but it is not working correctly shoe <- image_read('F:/photo.jpg') image_scale(shoe,'382x509') format width height colorspace filesize JPEG 382 460 sRGB 0 The…
Grv
  • 273
  • 3
  • 14
9
votes
4 answers

Select PHP's Image resizing algorithm

The function imagecopyresampled is useful to generate a thumbnail or resize images, while keeping aspect ratio: $fn = $_FILES['data']['tmp_name']; $size = getimagesize($fn); $width = $size[0]; $height = $size[1]; $ratio = $width / $height; if…
Basj
  • 41,386
  • 99
  • 383
  • 673