I found the reason why the #if'ed out version of the code doesn't work.

You're passing 0, 0 for the width and height values.  The libpng source has this check...

   if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
       height == NULL || bit_depth == NULL || color_type == NULL)
      return (0);

   *width = info_ptr->width;
   *height = info_ptr->height;
   *bit_depth = info_ptr->bit_depth;
   *color_type = info_ptr->color_type;

...I think this is a dumb check in libpng.  The width, height, bit_depth, and color_type should all be individually checked, not as a whole like this.  In my opinion, your code *should* work, but libpng has a stupid check and early return.  Maybe a patch to libpng is in order...