Get Image Height and Width as Integer Values

Get Image Height and Width as integer values?

Try like this:

list($width, $height) = getimagesize('path_to_image');

Make sure that:

  1. You specify the correct image path there
  2. The image has read access
  3. Chmod image dir to 755

Also try to prefix path with $_SERVER["DOCUMENT_ROOT"], this helps sometimes when you are not able to read files.

Get image height and width PHP

Should be

list($width, $height, $type, $attr) = getimagesize($_FILES["Artwork"]['tmp_name']);

See http://www.php.net/manual/en/features.file-upload.post-method.php

how can I get the size (height & width) of a image (link) with PHP

This is to find height and width of an image.

list($width, $height, $type, $attr) = getimagesize("image_name.jpg");
echo "Image width " .$width;
echo "<BR>";
echo "Image height " .$height;

Get image height from constrained width value image?

Its all about ratios. You already have the ratio of the width/height for the original. Now you just need to get it in terms of your 580px width. width/height is to 580/X

function getHeight($width,$height){ //originals 
return (580*$height)/$width;
}

Cannot use height and width from img.shape for further calculations

You just need to slap an int() function around those calculations of x, y, w, h. They're cast to floats when you divide.

How to sychronously get the width and height from a base64 string of image data?

This only works for png's
first thing first is to convert base64 do a buffer (Uint8array) then read the byte 16-20 (width) and 20-24 (height) as int32 value

function getPngDimensions(base64) {  let header = base64.slice(0, 50)  let uint8 = Uint8Array.from(atob(header), c => c.charCodeAt(0))  let dataView = new DataView(uint8.buffer, 0, 28)
return { width: dataView.getInt32(16), height: dataView.getInt32(20) }}
// Just to get some random base64 imagesvar random = (bottom, top) => Math.floor( Math.random() * ( 1 + top - bottom ) ) + bottomvar canvas = document.createElement('canvas')canvas.width = random(10, 100)canvas.height = random(10, 100)console.log(`canvas width: ${canvas.width}, height: ${canvas.height}`)var base64 = canvas.toDataURL().split(',')[1]console.log(base64)
var dimensions = getPngDimensions(base64)console.log(dimensions)

Width and Height values are automatically swapped after uploading to server. [PHP]

You can check first comment on exif_read_data function in php manual.

Code copied from there:

<?php
$image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
}
// $image now contains a resource with the image oriented correctly
?>


Related Topics



Leave a reply



Submit