hi guys i am using <input type='file' name='filett' size='filett'> and move the file into the temporary location. Just i wants to know how to get the image size using php . i am using $rect = thegetimagesize("img/flag.jpg"); but if i echo the variable $rect it shows the error
Use imagesx(), imagesy(), or getimagesize()
You mean the filesize or dimensions?
Dimensions
getimagesize() will get a bunch of info about an image. Easiest way to get width and height is to assign it to list($width, $height) language construct.
Filesize
filesize() will get the size of bytes in the file. Divide by 1024 to get kilobytes and so forth.
Related
I have a function to convert jpg image to tiff image, keep the original size and quality. I used Imagick class to do that. Convert success but image size has increment too much. My original image was taken from iPhone with 2.6Mb after converting, it increment to 36.6Mb.
I had tried to use some PHP image manipulation libraries like Intervention/image but nothing change.
I also test convert original jpg to new jpg and file size increment from 2.6Mb to 3.3Mb.
My code here:
$image = new \Imagick('image_path_file.jpg);
$image->setImageFormat("tiff");
$image->writeImage("path_new_file.tiff");
Have any options that can help Imagick not increment file size too much?
Thanks you 🙇♂️
Is it possible to resize an image in PHP, to a specified size in Kilobytes, with large images?
Example: IMGonline.com.ua
You can absolutely resize to a certain size using resize so if you know a certain number of pixels will be within that size you could set a pixel size. I've used 100x100 for reference.
$resize = new ResizeImage('image.png');
$resize->resizeTo(100, 100, 'exact');
$resize->saveImage('/resized/image.png');
Using this theory you could take the same approach and if an image is already that size or below you could resize it.
if ($file_size < 5000) {
$resize = new ResizeImage('image.png');
$resize->resizeTo(100, 100, 'exact');
$resize->saveImage('/resized/image.png');
} else {
// Error
}
So you could run it like this
// Upload Image
// Resize image
$resize = new ResizeImage('image.png');
$resize->resizeTo(100, 100, 'exact');
$resize->saveImage('/resized/image.png');
// Save image
// Open saved image
// Check image size
// Confirm or resize progressively smaller.
Hopefully the resize property is of some use. You've provided no code in your question but I think the best approach would be to check the size and save if it's fine then if not you would resize again and check again. Obviously you'd have to do this until it was at the correct size so execution time could take longer. I can't think of a direct way to compress the image with a php function unless you compressed the images instead of resizing them.
i know there is a lot of question in this topic, i tried almost every one procedure but my issue is still same...
Problem is
i am trying to upload an image file and want to get image height and image width, i search a lot and find that getimagesize will do it, but when i try this code
$file=$_FILES['myfile'];
list($width, $height) = getimagesize($file);
$file_width=$width;
$file_height=$height;
then this error is shown..
Warning: getimagesize() expects parameter 1 to be string, array given
After this error i search more about that function and the i try this code....
list($width, $height) = getimagesize($_FILES['myfile']['tmp_name']);
$file_width=$width;
$file_height=$height;
after executing the code nothing would happen...
** Update** Actually i am trying to get the image height and width and save the information in database. So i want that when user upload picture then before saving the information i get the height and width of image file and the other thing is that image source would be any this like from usp or memory card, so don't say me that to pass the full path as parameter in getimagesize(). Kindly provide me proper solution, if there is any other way to get the file height and width then refer me to it.
first you need to upload file then pass the uploaded location
getimagesize("location_of_file/".$file_name);
OR
getimagesize($path['path'].'/'.$_POST['name']);
OR
$file_name=$_FILES['fileToUpload']['name'];
getimagesize($target_dir.'/'.$file_name);
OR
$file_tmp=$_FILES['fileToUpload']['tmp_name'];
list($width, $height) = getimagesize($file_tmp);
$file_width=$width;
$file_height=$height;
Check this out. After you have completed the file upload, everything should be fine.
$temporary_name = $file['painting_picture']['tmp_name'];
if (is_uploaded_file($temporary_name)) {
list($width, $height, $type, $attr) = getimagesize($temporary_name);
}
You do not do anything with your data. Try to echo it:
if (isset($_FILES['myfile']['tmp_name'])) {
list($file_width, $file_height) = getimagesize($_FILES['myfile']['tmp_name']);
echo "The file dimensions is: width ".$file_width."px, height: ". $file_height."px";
}
CodeIgniter has a nice image manipulation class. I'm setting an image to be resized to a max of 200x200 pixels, with "master_dim" enabled to keep the aspect ratio the same. However, I don't see a way to get the new size of the image after it's done so that I can store it in the database. Does it not do this? Or do I have to use PHP's getimagesize() to do this?
Thanks.
$this->image_lib->resize() returns TRUE or FALSE.
You will need to use getimagesize on the new image to get its size after the resize.
I'm creating an image editor in JS/PHP, but now I'm having trouble. First of all, I load the image from the database (load a blob with imagecreatefromstring). Then I apply a list of actions to this image. But how can I get the image size from this image handler I have then? Without writing it to a file or use a stream object. How??
In case you mean the image dimensions:
$width = imagesx($imgHandle);
$height = imagesy($imgHandle);
See imagesx() and imagesy().
If you mean filesize, that's not possible without converting the GD resource to some image format (GIF, PNG, JPEG) because the format determines the image size in bytes.
I doubt you can since php gd image object is a generic object, without considerations on the compression that will be used for storage (png/jpg/bmp ...)