tommoor / fastimage

FastImage finds the dimensions or filetype of an image at a url by fetching the least data possible

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

not working?

sameronline opened this issue · comments

Thanks for your efforts, but it does not seem like the library is working? when i run the below function what i get is:

=======> http://www.google.com.eg/images/srpr/logo3w.png <======

FastImage:
Width: px Height: px in 0.92465806007385 seconds
Getimagesize:
Width: 275px Height: 95px in 0.47799015045166 seconds
=======> http://pcdn.500px.net/8123858/7051e2440a869a3fec74406a3aa200618452c390/4.jpg <======
FastImage:
Width: px Height: px in 1.06796002388 seconds
Getimagesize:
Width: 900px Height: 900px in 4.6637139320374 seconds
=======> http://farm3.staticflickr.com/2019/2354671896_8216677d61_o.jpg <======
FastImage:
Width: px Height: px in 1.3999531269073 seconds
Getimagesize:
Width: 1417px Height: 1063px in 7.8245828151703 seconds
=======> http://farm1.staticflickr.com/100/306618144_c2810214ee_b.jpg <======
FastImage:
Width: px Height: px in 4.7077901363373 seconds
Getimagesize:
Width: 1024px Height: 768px in 6.2303919792175 seconds

function GetSizeTest(){
  $path = libraries_get_path('fastimage');
  require_once($path."/Fastimage.php");

  $files = array(
    'http://www.google.com.eg/images/srpr/logo3w.png',
    'http://pcdn.500px.net/8123858/7051e2440a869a3fec74406a3aa200618452c390/4.jpg',
    'http://farm3.staticflickr.com/2019/2354671896_8216677d61_o.jpg',
    'http://farm1.staticflickr.com/100/306618144_c2810214ee_b.jpg'
  );

  foreach($files as $file){
    $uri = $file;
    echo "=======> $uri <======\n";
    $time = microtime(true);
    $image = new FastImage($uri);
    $image->load($uri);
    echo ">FastImage: \n";
    $size = $image->getSize();
    dsm($size);
    list($width, $height) = $size;
    echo "Width: ". $width . "px Height: ". $height . "px in " . (microtime(true)-$time) . " seconds \n";

    $time = microtime(true);
    list($width, $height) = getimagesize($uri);
    echo ">Getimagesize: \n";
    echo "Width: ". $width . "px Height: ". $height . "px in " . (microtime(true)-$time) . " seconds \n";
  }
}

Am i doing anything wrong or something wrong with the library?

Hi @sameronline - I'm not sure what the dsm function you are using is doing. I would drop that, you also only need to load the uri once, so i wouldn't pass it into the constructor in this case.

Let me know how it goes

Hello @tommoor Thanks for your quick response!

the dsm function is just a debugging function (we use it at Drupal), it's just pretty version of var_dump , it tried without it, and it does not work.

Do you have any other suggestions? Could you try the same code (without the dsm line) on your side and see if it's working?

Strange, I just tried and get the following output:

=======> http://www.google.com.eg/images/srpr/logo3w.png <======
>FastImage: 
Width: 275px Height: 95px in 0.099390029907227 seconds 
>Getimagesize: 
Width: 275px Height: 95px in 0.06046199798584 seconds 
=======> http://pcdn.500px.net/8123858/7051e2440a869a3fec74406a3aa200618452c390/4.jpg <======
>FastImage: 
Width: 900px Height: 900px in 0.149906873703 seconds 
>Getimagesize: 
Width: 900px Height: 900px in 0.62908005714417 seconds 
=======> http://farm3.staticflickr.com/2019/2354671896_8216677d61_o.jpg <======
>FastImage: 
Width: 1417px Height: 1063px in 0.16282510757446 seconds 
>Getimagesize: 
Width: 1417px Height: 1063px in 0.40223813056946 seconds 
=======> http://farm1.staticflickr.com/100/306618144_c2810214ee_b.jpg <======
>FastImage: 
Width: 1024px Height: 768px in 0.6636700630188 seconds 
>Getimagesize: 
Width: 1024px Height: 768px in 1.4150021076202 seconds 

Can you check your error logs? What version of PHP are you running? It would definitely be good to get to the bottom of this.

thanks @tommoor i would do this and let you know.

i tried once more, it's not working.

looking at both php and apache log error, nothing there.

about php version: #php -v returns PHP 5.3.6-13ubuntu3.9 with Suhosin-Patch (cli) (built: Sep 12 2012 19:02:11)

i'm going to try the same code on another server and let you know.

@tommoor

I tried the same code on a totally different server/machine, gives the same results. php -v on that server returns: PHP 5.3.15 (cli)

Do you have any suggestions on why this is happening? there is no errors anywhere.

Thanks for your time @tommoor

@tommoor i tried different way using this function https://gist.github.com/4136099 i wrote part of it, and found other parts online.. it's working for me on the same set of test images above

Ummm, i'm not sure what the best way to go about debugging this further is. I am biased but It would definitely be best to use Fastimage, it captures a lot of edge cases - for example the code in the gist will return the thumbnail size as the real size of a JPEG in some cases.

If it's not working across all of the different file formats that does narrow it down quite a bit. Do you have error reporting turned on?

error_reporting(E_ALL);

hello @tommoor i tried error_reporting(E_ALL) and still i get no errors or warning at all.

i'm using xdebug trying to debug the library to see where it stops, i will let you know if i found anything.

@tommoor using x-debug i found that the script is not able to find the type of the image and it fails at the "switch ($this->getChars(2))), and goes to the "default" case, where it returns false.

i'm debugging GetChars() function, which seems really find to me.

keep me updated :-)

@sameronline no luck on this one I take it?

@tommoor Sorry no i could not resolve it yet, maybe i will do later i will debug it again when i get back to using the library as i had to step away for something else at the moment.

Hi guys,

I was trying out Fastimage but it didn't work so I dived in and remove the 8bit encoding enforcement and it works.

    // we are dealing with bytes here, so force the encoding
    return mb_convert_encoding($result, "8BIT");

Any ideas?

@daohoangson, yepp, this mb_convert_encoding was wrong in my case as well. Works now without it! (php5.4)

Same issue here. Was working fine on my standalone test page. Then I moved it into one of my Laravel framework apps and it stopped working. In the function getChars($n) the difference between the two apps is strange. Showing output for JPEG using strToHex for debugging:

// standalone app
var_dump($this->strToHex($result)); // FFD8

// Laravel app
var_dump($this->strToHex($result)); // FFD8

// standalone app
var_dump($this->strToHex(mb_convert_encoding($result, "8BIT"))); // FFD8

// Laravel app
var_dump($this->strToHex(mb_convert_encoding($result, "8BIT"))); // FF

I am not sure why the last output is not FFD8 as expected. The server environment is not the issue since I am running it on the same machine. Not sure if there is an application level setting for this or something else.

Turns out Laravel uses Patchwork-UTF8 library which was causing the issues. Not sure if its a bug in the lib or within FastImage. I am commenting this line out as things seem to work fine without it.

For the others encountering, you may want to also check the mbstring configuration.

@aleemb, many thanks for your research and solution! I ran into the same issue today with our Laravel app. Cheers!

Any solution that will get it working for all? Happily accept a PR here