Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Resolved: Information not being displayed

images php coding issues or problems here.

Moderators: macek, egami, gesf

Resolved: Information not being displayed

Postby pewe » Fri Jun 01, 2012 7:57 am

I had need to combine 2 separate scrips (as detailed in another post now marked as resolved).

I have now managed to combine the 2 scripts and get them working together.

However I have one very strange problem.

- The function of the first script is to upload an image, create 2 new sizes of it and store all 3 images in separate directories on the server.

- The function of the second script is to read the Exif data from an image specified in the script and to then display the image and the exif data in a formatted page.

Independently these scripts work perfectly.

I have now modified the first script on completion of upload and storage of the image to load the location and name of the stored original image as a variable and then to run the second script.

I modified the second script to load the variable from the first script to identify the image to process instead of using a hard coded reference to the image and location.

The new combined script works as required EXCEPT for one problem.

In the second script, once the exif data is loaded from the image there is a calculation done on 2 of the elements and the results of the calculation are then displayed.

The results of this calculation are missing when I run the new script, but they show perfectly if I run the original script using hard coding to point to the same image the combined script uses.

The ONLY change I made to the second script was to the image location:

This in the stand alone version:

Code: Select all
// --- Change the 'image1.jpg' value below to the path of your file. --- //


$Image = 'original/test.jpg';

// --- Read EXIF Data --- //

$exif = exif_read_data($Image, 0, true);

// --- The EXIF GPS Conversion Degrees to Decimal --- //

function toDecimal($deg, $min, $sec, $hemi) {
 $d = $deg + $min/60 + $sec/3600;
 return ($hemi=='S' || $hemi=='W') ? $d*=-1 : $d;
}

function divide($a) {
 $e = explode('/', $a);
 if (!$e[0] || !$e[1]) {
  return 0;
 } else {
  return $e[0] / $e[1];
 }
}

function getGPS() {
 global $exif;
 if ($exif) {  $lat = $exif['GPS']['GPSLatitude'];
 $log = $exif['GPS']['GPSLongitude'];
  if (!$lat || !$log) return null;
  $lat_degrees = divide($lat[0]);
  $lat_minutes = divide($lat[1]);
  $lat_seconds = divide($lat[2]);
  $lat_hemi = $exif['GPS']['GPSLatitudeRef'];
  $log_degrees = divide($log[0]);
  $log_minutes = divide($log[1]);
  $log_seconds = divide($log[2]);
  $log_hemi = $exif['GPS']['GPSLongitudeRef'];
  $lat_decimal = toDecimal($lat_degrees, $lat_minutes, $lat_seconds, $lat_hemi);
  $log_decimal = toDecimal($log_degrees, $log_minutes, $log_seconds, $log_hemi);
  return array($lat_decimal, $log_decimal);
 } else{
  return null;
 }
}


This is the modified version;

Code: Select all
// --- Change the 'image1.jpg' value below to the path of your file. --- //


$Image = $Image99;

// --- Read EXIF Data --- //

$exif = exif_read_data($Image, 0, true);

// --- The EXIF GPS Conversion Degrees to Decimal --- //

function toDecimal($deg, $min, $sec, $hemi) {
 $d = $deg + $min/60 + $sec/3600;
 return ($hemi=='S' || $hemi=='W') ? $d*=-1 : $d;
}

function divide($a) {
 $e = explode('/', $a);
 if (!$e[0] || !$e[1]) {
  return 0;
 } else {
  return $e[0] / $e[1];
 }
}

function getGPS() {
 global $exif;
 if ($exif) {  $lat = $exif['GPS']['GPSLatitude'];
 $log = $exif['GPS']['GPSLongitude'];
  if (!$lat || !$log) return null;
  $lat_degrees = divide($lat[0]);
  $lat_minutes = divide($lat[1]);
  $lat_seconds = divide($lat[2]);
  $lat_hemi = $exif['GPS']['GPSLatitudeRef'];
  $log_degrees = divide($log[0]);
  $log_minutes = divide($log[1]);
  $log_seconds = divide($log[2]);
  $log_hemi = $exif['GPS']['GPSLongitudeRef'];
  $lat_decimal = toDecimal($lat_degrees, $lat_minutes, $lat_seconds, $lat_hemi);
  $log_decimal = toDecimal($log_degrees, $log_minutes, $log_seconds, $log_hemi);
  return array($lat_decimal, $log_decimal);
 } else{
  return null;
 }
}

 $gps = getGPS();


$Image99 in the second set of code is the location of the image defined as a variable in the upload part of the script - and is the same image used in the standalone script.

So - can anyone point me in the direction of how to locate the problem with the combined script.

Here's hoping for some guidance.
Last edited by pewe on Tue Jun 05, 2012 7:01 am, edited 1 time in total.
pewe
New php-forum User
New php-forum User
 
Posts: 16
Joined: Fri May 25, 2012 6:05 am

Re: Information not being displayed

Postby ejsexton82 » Tue Jun 05, 2012 5:41 am

It sounds like the value from $Image99 my be coming from another script. Are you sure that the value is carrying over to this script?

Code: Select all
var_dump($Image99);


If not, something like this may help:

Code: Select all
global $Image99;
$Image = $Image99;
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Re: Information not being displayed

Postby pewe » Tue Jun 05, 2012 7:00 am

Sorry ejsexton

I meant to post that this problem was resolved.

Not sure why it worked, but moving point where I inserted the script to set the variable $Image99 (as well as the 'include' for the second script) cured the problem. I put them at the end of the script and when the second script ran the calculation showed on the page. :?
pewe
New php-forum User
New php-forum User
 
Posts: 16
Joined: Fri May 25, 2012 6:05 am

Re: Information not being displayed

Postby ejsexton82 » Tue Jun 05, 2012 10:22 am

pewe wrote:Sorry ejsexton

I meant to post that this problem was resolved.

Good deal!
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.