Image resizing client-side with JavaScript before upload to the server

Here’s a gist which does this: https://gist.github.com/dcollien/312bce1270a5f511bf4a (an es6 version, and a .js version which can be included in a script tag) You can use it as follows: <input type=”file” id=”select”> <img id=”preview”> <script> document.getElementById(‘select’).onchange = function(evt) { ImageTools.resize(this.files[0], { width: 320, // maximum width height: 240 // maximum height }, function(blob, didItResize) { // … Read more

Android: How to Programmatically set the size of a Layout

Java This should work: // Gets linearlayout LinearLayout layout = findViewById(R.id.numberPadLayout); // Gets the layout params that will allow you to resize the layout LayoutParams params = layout.getLayoutParams(); // Changes the height and width to the specified *pixels* params.height = 100; params.width = 100; layout.setLayoutParams(params); If you want to convert dip to pixels, use this: … Read more

WPF: Setting the Width (and Height) as a Percentage Value

You can put the textboxes inside a grid to do percentage values on the rows or columns of the grid and let the textboxes auto-fill to their parent cells (as they will by default). Example: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width=”2*” /> <ColumnDefinition Width=”3*” /> </Grid.ColumnDefinitions> <TextBox Grid.Column=”0″ /> <TextBox Grid.Column=”1″ /> </Grid> This will make #1 … Read more

Numpy Resize/Rescale Image

Yeah, you can install opencv (this is a library used for image processing, and computer vision), and use the cv2.resize function. And for instance use: import cv2 import numpy as np img = cv2.imread(‘your_image.jpg’) res = cv2.resize(img, dsize=(54, 140), interpolation=cv2.INTER_CUBIC) Here img is thus a numpy array containing the original image, whereas res is a … Read more

How to resize images proportionally / keeping the aspect ratio?

I think this is a really cool method: /** * Conserve aspect ratio of the original region. Useful when shrinking/enlarging * images to fit into a certain area. * * @param {Number} srcWidth width of source image * @param {Number} srcHeight height of source image * @param {Number} maxWidth maximum available width * @param {Number} … Read more

How to resize an image with OpenCV2.0 and Python2.6

If you wish to use CV2, you need to use the resize function. For example, this will resize both axes by half: small = cv2.resize(image, (0,0), fx=0.5, fy=0.5) and this will resize the image to have 100 cols (width) and 50 rows (height): resized_image = cv2.resize(image, (100, 50)) Another option is to use scipy module, … Read more

Resize a large bitmap file to scaled output file on Android

No. I’d love for someone to correct me, but I accepted the load/resize approach you tried as a compromise. Here are the steps for anyone browsing: Calculate the maximum possible inSampleSize that still yields an image larger than your target. Load the image using BitmapFactory.decodeFile(file, options), passing inSampleSize as an option. Resize to the desired … Read more