Question : Know the image type?

I am parsing some pages on a government site and they contain image links like
this:
1:
2:
image_render.aspx?item=011739056&sz=lg

When I navigate to this URL, it doesn't show the image, it shows code:
¿¿¿¿¿ JFIF¿ ¿d¿d¿¿¿¿¿

I have used this code in the past to get these images but I have no idea how to determine the image TYPE because some of them are GIF.

Using simple_html_dom class to parse the HTML after Tidy'ing it up.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
$image = $html2->getElementById('hlHeadImage');
if (isset($image)) {
  if (strpos($image->children(0)->src, 'clearpixel') == 0) {
    $link = $image->children(0)->src;
    $path_parts = pathinfo($link);
    $ext = $path_parts['extension'];
    $image_path =  "part_images/".$ITEM_NO.".".$ext;
    @copy($link."&sz=lg", $image_path);
  }
} else {
  $image = $html2->getElementById('hlLargeImage');
  if (isset($image)) {
    if (strpos($image->children(0)->src, 'clearpixel') == 0) {
      $link = $image->children(0)->src;
      $path_parts = pathinfo($link);
      $ext = $path_parts['extension'];
      $image_path =  "part_images/".$ITEM_NO.".".$ext;
      @copy($link, $image_path);
    }
  }
}

Question is, how can I download these images and maintain the extension?

Answer : Know the image type?

Hi learningunix,

the line checks if the left-most byte of 'num' is '1'.

'&num' is a pointer to the memory address where the first byte of 'num' resides. The '(char*)' casts this pointer '&num' (which is a pointer to int) to a pointer to char. Since char is a one byte data type accessing that 'pointer to char' with '*' accesses the first byte of the int. In little endian this byte has to be '1' for and 'int' which is '1' - in big endian the first byte would be '0' since the least significant byte is the most right one ...

Hope that helps,

ZOPPO

Random Solutions  
 
programming4us programming4us