Android Question image height and width while still on server?

Todd Carlton

Member
Licensed User
Longtime User
Hello Community!

This one has me stumped. I admit up front that I don't even have any trial code to post. Apologies.

How would I get the height and width (in px) of a .jpg from a server without downloading it first?

The .jpg is on a server that can be accessed via browser or FTP. Access is easy. The answer eludes me.

Thank you for any direction; especially links to study.

-OCS
 

DonManfred

Expert
Licensed User
Longtime User
@Todd Carlton btw: WELCOME to basic4android community!



PHP:
<?php
header("content-type: text/plain");
$result = array();

foreach (glob('/path/to/images/*.png') as $filename) {
    $thisfile = array();

    $path_parts = pathinfo($filename);

    $thisfile["filename"] = $path_parts['basename'];
    $thisfile["ext"] = $path_parts['extension'];
    #echo $filename." - Größe: " . filesize($filename) . "\n";
    $size = getimagesize( $filename);
  $thisfile["width"] = $size[0];
  $thisfile["height"] = $size[1];
  # echo "Bildbreite: " . $size[0];
  # echo "Bildhöhe: " . $size[1];
  $result[] = $thisfile;
}
echo json_encode($result);
?>


sample output

Code to parse this jsonstring (for ex in a httpjobs Jobdone-sub)
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
  Dim height As Int = colroot.Get("height")
  Dim width As Int = colroot.Get("width")
  Dim filename As String = colroot.Get("filename")
  Dim ext As String = colroot.Get("ext")
Next

As you are new to B4A i´ll show you a complete example on how to do call the above php-script on a server and getting the result from it back to your app.
Please find the example attached.

See basic4android log for results (the app don´t have a layout)

 

Attachments

  • getimagesizes.zip
    6.5 KB · Views: 138
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…