Questions tagged [getimagesize]

194 questions
58
votes
3 answers

PHP check if file is an image

Is there a way to make sure a received file is an image in PHP? Testing for the extension doesn't sound very secure to me as you could upload a script and change its extension to whatever you want. I've tried to use getimagesize too, but there might…
sf89
  • 4,570
  • 7
  • 20
  • 27
40
votes
3 answers

Super fast getimagesize in php

I am trying to get image size (image dimensions, width and height) of hundreds of remote images and getimagesize is way too slow. I have done some reading and found out the quickest way would be to use file_get_contents to read a certain amount of…
Sir Lojik
  • 1,341
  • 6
  • 22
  • 44
21
votes
4 answers

Handle error when getimagesize can't find a file

when I'm trying to getimagesize($img) and the image doesn't exist, I get an error. I don't want to first check whether the file exists, just handle the error. I'm not sure how try catch works, but I want to do something like: try: getimagesize($img)…
Johan
  • 17,688
  • 30
  • 67
  • 88
21
votes
7 answers

Android: bitmap.getByteCount() in API lesser than 12

When i searched for how to find the size of an image before saving it on the SD card, i found this: bitmap.getByteCount(); but that method is added in API 12 and i am using API 10. So again i found out this: getByteCount() is just a convenience…
Archie.bpgc
  • 22,633
  • 38
  • 142
  • 219
12
votes
8 answers

What kind of file types does PHP getimagesize() return?

Does anyone know all the possible results for the 3rd value returned from PHP's getimagesize() function? Example this code below will return: $imageinfo['2'] = 2; for a jpg image, $imageinfo['2'] = 3; for a png image, $imageinfo['2'] = 0; for a gif…
JasonDavis
  • 45,100
  • 92
  • 294
  • 508
9
votes
1 answer

PHP getimagesize() mixes up width and height

I use a PHP script that uploads an image, then gets the dimensions with PHP's getImageSize() and then does things to the image according to the pictures orientation (portrait or landscape). However (PHP version 5.4.12) on some .jpg files it gets the…
Chiel
  • 91
  • 1
  • 2
8
votes
1 answer

PHP getimagesize - Failed to open stream. Bad request

I am getting the following error: getimagesize(https://static1.squarespace.com/static/570d03d02b8dde8b2642afca/570f74e87c65e4819dec6812/57272dbfb6aa606f78a5d8b5/1470397291105/4XTRYCK3.jpg): failed to open stream: HTTP request failed! HTTP/1.1 400…
alieninlondon
  • 860
  • 2
  • 11
  • 33
7
votes
6 answers

php get the KB size of an image

i've been googleing but all i get is getimagesize and filesize. getimagesize dosent get the KB size just width and height which is not what im looking for. filesize give me the message Warning: filesize() [function.filesize]: stat failed for the…
Macao
  • 81
  • 1
  • 1
  • 3
6
votes
1 answer

How to get the width and height of an image by Url in Google Sheets

I have in a Google Sheet a list of images by URL. Images are on a remote server. I got the preview in my Sheet by the Image (URL) function. Is there a way to get the width and height of each remote image in each row by formula or script?
5
votes
1 answer

file_exists or getimagesize only work with local, absolute file paths, but not with URLs in PHP

I recently updated one of my servers and since then, I have an issue with some specific PHP commands (see below). I believe it is a configuration issue, but I already looked into a couple of things and do not know any further. So maybe one of you…
Sebastian
  • 109
  • 6
5
votes
3 answers

PHP function getimagesize() gives "Read error" when trying to get https url

I am trying to use getimagesize with URL and with http everything is fine. However when trying to use function on https url I am getting "Read error" Notice and false as result. I checked and I have OpenSSL 0.98 installed on the server (so it should…
Goran
  • 2,523
  • 2
  • 26
  • 29
5
votes
1 answer

PHP is_readable returns true for non-readable file

I have an image processor PHP script, and it contains the following code: if (!is_dir($fullFile)) { if (is_readable($fullFile)) { $im = getimagesize($fullFile); // Will be FALSE if not an image In some instances,…
Dennis
  • 810
  • 2
  • 13
  • 30
4
votes
2 answers

Javascript get image size from php generated image

I found this code to get the image size on javascript: function getImgSize(imgSrc) { var newImg = new Image(); newImg.src = imgSrc; var height = newImg.height; var width = newImg.width; alert ('The image size is…
Luan Nico
  • 4,792
  • 2
  • 27
  • 50
4
votes
2 answers

PHP Get Image size when image is stored as byte array

I have image as binary string. (submitted via POST from C# app as byte array) I can read it using imagecreatefromstring function. How can I get image size (width and height)? getimagesize function takes filename as parametar. Is there alternative…
Emir
  • 1,586
  • 2
  • 16
  • 32
4
votes
2 answers

PHP's getimagesize not detecting image from URL

I'm using the following code to quickly verify whether a link is an image or not... if (getimagesize($imageLink)) { } else { echo "notImage"; exit(); } It works in practically all cases (i.e. if the browser returns an image, then…
d3wannabe
  • 981
  • 1
  • 9
  • 28
1
2 3
12 13