Jump to content

pewe

Members
  • Posts

    27
  • Joined

  • Last visited

Everything posted by pewe

  1. 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: // --- 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; } } $gps = getGPS(); This is the modified version; // --- 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.
  2. I have 2 scripts that I have managed to et working independently, and now need to combine them. The first script is an image uploader - which uploads images, stores the original plus a resized image plus a thumbnail. The second script reads the Exif data of an image and displays it. The image name that is read is hard coded in the script. What I would like is to have the second script load automatically on completion of the upload and read the information from the uploaded image. I have no experience of coding and although I can find my way around the simle scips I ave no idea where to start with the combining of these two. If anyone can point me in the right direction it would be much appreciated. The first script is i two parts, the html page and the php script called. The html content: <?php require_once("maxImageUpload.class.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Image Uploader</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $myImageUpload = new maxImageUpload(); //$myUpload->setUploadLocation(getcwd().DIRECTORY_SEPARATOR); $myImageUpload->uploadImage(); ?> </body> Here is the file called (maxImageUpload.class.php) <?php /************************************************* * Image Uploader * * Version: 1.0 * * ****************************************************/ class maxImageUpload { // Maximum upload size var $maxUploadSize = 15; // 10 Mb // Image sizes var $normalWidth = 1200; var $normalHeight = 900; var $thumbWidth = 128; var $thumbHeight = 96; // Image quality var $imageQualityNormal = 3; //1:Poor ... 5:Very good var $imageQualityThumb = 1; //1:Poor ... 5:Very good // Directories to store images var $baseDir = ''; var $originalDir = 'original'; var $normalDir = 'normal'; var $thumbDir = 'thumbnail'; // File postfixes var $originalPrefix = ''; var $normalPrefix = 'normal_'; var $thumbPrefix = 'thumb_'; // Internal used variables var $error = ''; var $maxMemoryUsage = 128; // 128 Mb /** * Constructor to initialize class varaibles * The upload locations will be set to the actual * working directory * * @return maxImageUpload */ function maxImageUpload(){ if (!file_exists($this->baseDir)) { if (!@mkdir($this->baseDir)){ $this->baseDir = getcwd(); } } $this->originalDir = $this->baseDir.DIRECTORY_SEPARATOR.$this->originalDir.DIRECTORY_SEPARATOR; if (!file_exists($this->originalDir)) { mkdir($this->originalDir); } $this->normalDir = $this->baseDir.DIRECTORY_SEPARATOR.$this->normalDir.DIRECTORY_SEPARATOR; if (!file_exists($this->normalDir)) { mkdir($this->normalDir); } $this->thumbDir = $this->baseDir.DIRECTORY_SEPARATOR.$this->thumbDir.DIRECTORY_SEPARATOR; if (!file_exists($this->thumbDir)) { mkdir($this->thumbDir); } } /** * This function sets the directory where to upload the file * In case of Windows server use the form: c:\\temp * In case of Unix server use the form: /tmp * * @param String Directory where to store the files */ function setUploadBaseLocation($dir){ $this->baseDir = $dir; } function showUploadForm($msg='',$error=''){ ?> <div id="container"> <div id="header"><div id="header_left"></div> <div id="header_main">Image Uploader</div><div id="header_right"></div></div> <div id="content"> <?php if ($msg != ''){ echo '<p class="msg">'.$msg.'</p>'; } else if ($error != ''){ echo '<p class="emsg">'.$error.'</p>'; } ?> <form action="" method="post" enctype="multipart/form-data" > <center> <label>File: <input name="myfile" type="file" size="30" /> </label> <label> <input type="submit" name="submitBtn" class="sbtn" value="Upload" /> </label> </center> </form> </div> <div id="footer"><a href="http://www.ukf.com" target="_blank">Images are Copywrite Of Uploader</a></div> </div> <?php } function uploadImage(){ $result = true; if (!isset($_POST['submitBtn'])){ $this->showUploadForm(); } else { $msg = ''; $error = ''; //Check image type. Only jpeg images are allowed if ( (($_FILES['myfile']['type'])=='image/pjpeg') || (($_FILES['myfile']['type'])=='image/jpeg')) { // Check the output directories if ($this->checkDirs()){ $target_path = $this->originalDir . basename( $_FILES['myfile']['name']); if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) { $msg = basename( $_FILES['myfile']['name']). " (".filesize($target_path)." bytes) was stored!"; } else{ $error = "The upload process failed!"; $result = false; } // Store resized images if ($result){ $this->setMemoryLimit($target_path); // Create normal size image $dest = $this->normalDir.$this->normalPrefix.basename($_FILES['myfile']['name']); $this->resizeImage($target_path,$dest,$this->normalWidth,$this->normalHeight,$this->imageQualityNormal); $msg .= "<br/>".basename($dest)." (".filesize($dest)." bytes) was stored!"; // Create thumbnail image $dest = $this->thumbDir.$this->thumbPrefix.basename($_FILES['myfile']['name']); $this->resizeImage($target_path,$dest,$this->thumbWidth,$this->thumbHeight,$this->imageQualityThumb); $msg .= "<br/>".basename($dest)." (".filesize($dest)." bytes) was stored!"; } } } else { echo "Only jpeg images are allowed!"; } $this->showUploadForm($msg,$error); } } function checkDirs(){ $result = true; if (!file_exists($this->originalDir)){ $this->error = "The target directory ($this->originalDir) doesn't exists!"; $result = false; } else if (!is_writeable($this->originalDir)) { $this->error = "The target directory ($this->originalDir) is not writeable!"; $result = false; } else if (!is_writeable($this->normalDir)) { $this->error = "The target directory ($this->normalDir) is not writeable!"; $result = false; } else if (!is_writeable($this->normalDir)) { $this->error = "The target directory ($this->normalDir) is not writeable!"; $result = false; } else if (!is_writeable($this->thumbDir)) { $this->error = "The target directory ($this->thumbDir) is not writeable!"; $result = false; } else if (!is_writeable($this->originalDir)) { $this->error = "The target directory ($this->thumbDir) is not writeable!"; $result = false; } return $result; } function setMemoryLimit($filename){ $width = 0; $height = 0; $size = ini_get('memory_limit'); list($width, $height) = getimagesize($filename); $size = $size + floor(($width * $height * 4 * 1.5 + 1048576) / 1048576); if ($size > $this->maxMemoryUsage) $size = $this->maxMemoryUsage; ini_set('memory_limit',$size.'M'); } function resizeImage($src,$dest,$new_width,$new_height,$quality){ $width = 0; $height = 0; list($width, $height) = getimagesize($src); $newImage = imagecreatetruecolor($new_width, $new_height); $oldImage = imagecreatefromjpeg($src); $this->fastimagecopyresampled($newImage, $oldImage, 0, 0, 0, 0, $new_width, $new_height, $width, $height, $quality); imagejpeg($newImage, $dest, 100); } // Function to resize images function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) { if (empty($src_image) || empty($dst_image)) { return false; } if ($quality <= 1) { $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1); imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h); imagedestroy ($temp); } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) { $tmp_w = $dst_w * $quality; $tmp_h = $dst_h * $quality; $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1); imagecopyresized ($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h); imagecopyresampled ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h); imagedestroy ($temp); } else { imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } return true; } } ?> And here is the first few lines of the third file: <? // +++++++++++++++++++++++++ // // +++++++ EXTRACT EXIF +++++++ // // +++++++++++++++++++++++++ // // --- Change the 'image.jpg' value below to call the file required file. --- // $Image = 'image.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; In the third file, when it loads after completion of the upload I need it to call the original image and read the exif data from that. Sorry for the lengthy post, but hopefully someone will be able to analyse it and advise me on how to move forward. Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.