Jump to content

pewe

Members
  • Posts

    27
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

pewe's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. It's OK. Found the answer - problem resolved. Thanks for input.
  2. Thanks for the response JC. I tried adding your suggestion to my script but unfortunately it returns errors in the 'included' script that is used to write back to the photo. In my haste I copied what you placed above - with no results at all (not even entries in the error log). I then realised that the $data may well need changing to $exif_data in my situation. However when I used that the error log reported EXIF.php is the script which is called to read/write the metadata. The relevant lines contain: So now I am stumped
  3. Update: I have managed to view the content of the array '$exif_data' and the part I need to alter is the part of the array containing the the size. There are 2 variables in the resize script which are $new_width, $new_height I need these to replace the values in the array which are shown below as '2000' and '1500' [40962] => Array ( [Tag Number] => 40962 [Tag Name] => Pixel X Dimension [Tag Description] => [Data Type] => 4 [Type] => Numeric [Units] => pixels [Data] => Array ( [0] => 2000 ) [Text Value] => 2000 pixels [Decoded] => 1 ) [40963] => Array ( [Tag Number] => 40963 [Tag Name] => Pixel Y Dimension [Tag Description] => [Data Type] => 4 [Type] => Numeric [Units] => pixels [Data] => Array ( [0] => 1500 ) [Text Value] => 1500 pixels [Decoded] => 1 ) I am not sure how to code this to replace the correct part of the content. Any assistance/suggestions appreciated?
  4. In a previous post I explained a problem I was having extracting metadata from a photo and then adding it back after resizing the photo. I managed to solve that problem but have since discovered another issue. When I resize the image the exif data written back to it contains the original size and what I need to store is the new size - but I am now completely lost as to how to go about doing this. The command to extract the data from the image before resizing is $exif_data = get_EXIF_JPEG( $filename ); The function 'get_EXIF_JPEG' is not a standard PHP function, but one contained in a separate file (EXIF.php) called as an 'include' in the resizing script. However I assume that the information is called into an array because a later instruction put_EXIF_JPEG( $exif_data, $jpeg_header_data ); writes it 'as is' back to the new image. How can I : - determine the structure/content of the array - alter some of the content (ie the size information) before writing it back to the new image. Any and all assistance appreciated. This is the function 'get_EXIF_JPEG' from the included script: function get_EXIF_JPEG( $filename ) { // Change: Added as of version 1.11 // Check if a wrapper is being used - these are not currently supported (see notes at top of file) if ( ( stristr ( $filename, "http://" ) != FALSE ) || ( stristr ( $filename, "ftp://" ) != FALSE ) ) { // A HTTP or FTP wrapper is being used - show a warning and abort echo "HTTP and FTP wrappers are currently not supported with EXIF - See EXIF functionality documentation - a local file must be specified<br>"; echo "To work on an internet file, copy it locally to start with:<br><br>\n"; echo "\$newfilename = tempnam ( \$dir, \"tmpexif\" );<br>\n"; echo "copy ( \"http://whatever.com\", \$newfilename );<br><br>\n"; return FALSE; } // get the JPEG headers $jpeg_header_data = get_jpeg_header_data( $filename ); // Flag that an EXIF segment has not been found yet $EXIF_Location = -1; //Cycle through the header segments for( $i = 0; $i < count( $jpeg_header_data ); $i++ ) { // If we find an APP1 header, if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP1" ) == 0 ) { // And if it has the EXIF label, if ( ( strncmp ( $jpeg_header_data[$i]['SegData'], "Exif\x00\x00", 6) == 0 ) || ( strncmp ( $jpeg_header_data[$i]['SegData'], "Exif\x00\xFF", 6) == 0 ) ) // For some reason, some files have a faulty EXIF name which has a 0xFF in it { // Save the location of the EXIF segment $EXIF_Location = $i; } } } // Check if an EXIF segment was found if ( $EXIF_Location == -1 ) { // Couldn't find any EXIF block to decode return FALSE; } $filehnd = @fopen($filename, 'rb'); // Check if the file opened successfully if ( ! $filehnd ) { // Could't open the file - exit echo "<p>Could not open file $filename</p>\n"; return FALSE; } fseek( $filehnd, $jpeg_header_data[$EXIF_Location]['SegDataStart'] + 6 ); // Decode the Exif segment into an array and return it $exif_data = process_TIFF_Header( $filehnd, "TIFF" ); // Close File fclose($filehnd); return $exif_data; }
  5. I resolved the problem which was (apparently) a simple but crucial oversight. I needed to call the header data from the new resized file before adding the info from the original file back to it - I needed to add '$jpeg_header_data = get_jpeg_header_data( $filename );' like seen below. $jpeg_header_data = get_jpeg_header_data( $filename ); $jpeg_header_data = put_EXIF_JPEG( $exif_data, $jpeg_header_data ); put_jpeg_header_data( $filename, $filename, $jpeg_header_data ); But there is one more issue, but that is subject of another thread.
  6. My first post was an extract of the parts I added to my original resize script to : - check the metadata in the original image by displaying it - write the metadata to the resized image (which was saved using the same name and overwriting the original image. My second post was the complete resize script including the additions. As I mentioned in my original post, my coding skills are very basic so I guess you are saying that the code is not right. The variable $filename contains the name of the original image before resizing and from which the metatada is taken using $exif_data = get_EXIF_JPEG( $filename ); So as the image is saved over the original using the same name I thought that the code to write it back to this file would be $jpeg_header_data = put_EXIF_JPEG( $exif_data, $jpeg_header_data ); put_jpeg_header_data( $filename, $filename, $jpeg_header_data ); Obviously this is not correct as it does not work, and I'm not sure what it needs to be changed to.
  7. There is this or this or do a google search for cookie scripts and you will find quite a few other alternatives.
  8. Forgive me , but my coding knowledge is somewhat limited, the original resize script was written for me and I cannot get hold of the coder. However, as the resized image is overwriting the original it will have the same name as it did originally. I therefore concluded that as the first part of the script is reading and displaying the Exif Data using $filename, that when writing the data using $filename should find the file also. This is the full script: The parts marked 'For Testing Only' are where the exif is printed from the photo (this will be removed in final working script). The first time it is used it is running on the original image and it displays content. The second time it is run it should be running on the same photo, just resized - but nothing is displayed, and when I check the file the data has not been written back to it. <?php // added for exif extraction and re-writing // Change: Allow this example file to be easily relocatable - as of version 1.11 $Toolkit_Dir = "./"; // Ensure dir name includes trailing slash // Hide any unknown EXIF tags $GLOBALS['HIDE_UNKNOWN_TAGS'] = TRUE; include $Toolkit_Dir . 'Toolkit_Version.php'; // Change: added as of version 1.11 include $Toolkit_Dir . 'JPEG.php'; // Change: Allow this example file to be easily relocatable - as of version 1.11 include $Toolkit_Dir . 'JFIF.php'; include $Toolkit_Dir . 'PictureInfo.php'; include $Toolkit_Dir . 'XMP.php'; include $Toolkit_Dir . 'Photoshop_IRB.php'; include $Toolkit_Dir . 'EXIF.php'; // original resize script //use this line if you get the error message of using too much memory (strip '//') //ini_set ( "memory_limit", "48M"); $percent = 0.5; // specify propotion for resized image here if (ob_get_level() == 0) ob_start(); if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $destination_path = './'; $target_path = $destination_path . basename($file); $extension = pathinfo($target_path); $allowed_ext = "jpg, gif, png, bmp, jpeg, JPG"; $extension = $extension[extension]; $allowed_paths = explode(", ", $allowed_ext); $ok = 0; for($i = 0; $i < count($allowed_paths); $i++) { if ($allowed_paths[$i] == "$extension") { $ok = "1"; } } if ($ok == "1") { if($extension == "jpg" || $extension == "jpeg" || $extension == "JPG"){ $tmp_image=imagecreatefromjpeg($target_path); } if($extension == "png") { $tmp_image=imagecreatefrompng($target_path); } if($extension == "gif") { $tmp_image=imagecreatefromgif($target_path); } $width = imagesx($tmp_image); $height = imagesy($tmp_image); //calculate the image ratio not used if using proportion rather than new physical sizes $imgratio = ($width / $height); if ($imgratio>1) { $new_width = $width * $percent; $new_height = $height * $percent; } else { $new_width = $width * $percent; $new_height = $height * $percent; } // For testing only // Print value held by $file - and use to create variable $filename - print exif from $filename to confirm it exists. echo " $file <br> " ; $filename = $file; $exif_data = get_EXIF_JPEG( $filename ); echo Interpret_EXIF_to_HTML( get_EXIF_JPEG( $filename ), $filename ); // end of testing $new_image = imagecreatetruecolor($new_width,$new_height); ImageCopyResized($new_image, $tmp_image,0,0,0,0, $new_width, $new_height, $width, $height); //Grab new image imagejpeg($new_image, $target_path); $image_buffer = ob_get_contents(); ImageDestroy($new_image); ImageDestroy($tmp_image); echo " $file resized to $new_width x $new_height <br> \n"; echo str_pad('',4096)."\n"; $jpeg_header_data = put_EXIF_JPEG( $exif_data, $jpeg_header_data ); put_jpeg_header_data( $filename, $filename, $jpeg_header_data ); // For testing only $exif_data = get_EXIF_JPEG( $filename ); echo Interpret_EXIF_to_HTML( get_EXIF_JPEG( $filename ), $filename ); // end of testing ob_flush(); flush(); } } } closedir($handle); echo "Done."; ob_end_flush(); } ?>
  9. I have a PHP script which scans a directory for images, resizes any it finds and saves them back overwriting the originals. It works well except for the fact that it strips the metadata from the image. I found a Toolkit which can manipulate Metadata including extracting and writing it to images. On this page it explains how to do this (at the bottom of the page). So I added it to my code but am having problems - it does not write the metadata to the resized image. I am obviously missing something but can't seem to figure out what (probably my lack of coding skill) and wondered if someone can spot my error and suggest a correction. Here is the relevant part of the code: This code is first used just to confirm what images are found in the directory and contain metadata - by printing it in an html format echo " $file <br> " ; $filename = $file; $exif_data = get_EXIF_JPEG( $filename ); echo Interpret_EXIF_to_HTML( get_EXIF_JPEG( $filename ), $filename ); Here is the code which then resizes the image and saves it, and should write the metadata to it - but doesn't seem to work $new_image = imagecreatetruecolor($new_width,$new_height); ImageCopyResized($new_image, $tmp_image,0,0,0,0, $new_width, $new_height, $width, $height); //Grab new image imagejpeg($new_image, $target_path); $image_buffer = ob_get_contents(); ImageDestroy($new_image); ImageDestroy($tmp_image); echo " $file resized to $new_width x $new_height <br> \n"; echo str_pad('',4096)."\n"; $jpeg_header_data = put_EXIF_JPEG( $exif_data, $jpeg_header_data ); put_jpeg_header_data( $filename, $filename, $jpeg_header_data ); ob_flush(); flush(); Is this a case of having put the rewrite code in the wrong place - or something else? Thanks for any suggestions which may help.
  10. Ok, I found the problem - nothing to do with the database access, it was a script function that MySql didn't like. So can now move on and test out the rest of the script.
  11. Operating system: Linux PHP: 5.3.22 [2013-04-13 02:02:51] MySQL: 5.1.68-cll [2013-04-12 20:02:51] Not sure I'm with you on that. Which code are you referring to. The code I posted above had 9 @ signs in it. It's 2 am here now and I have an early start in the morning (hospital run to visit my son). I have attached a copy of the file for anyone who may have the time (and hopefully inclination) to cast an eye - just in case there is an obvious and simple answer. Quick_CSV_import.zip
  12. Thanks Barand - that makes sense. I removed the error control and still get the error message If I misspell the database username I get a message (set in the script) to the effect that the script cannot connect. Once I correct the spelling mistake I get further and the upload form is displayed. As soon as the file uploads the script stops with the above error at the point where it should be producing a list of the uploaded file headers and a list of the field headers from the mysql table.
  13. There are in fact 9 places in the code where the @ symbol appears - none of which have any wording which relates to an error - $res =@mysql_query($sql) (x 4) - @mysql_escape_string($this->file_name)); - "LOAD DATA INFILE '".@mysql_escape_string($this->file_name). "' INTO TABLE `".$this->table_name. "` FIELDS TERMINATED BY '".@mysql_escape_string($this->field_separate_char). "' OPTIONALLY ENCLOSED BY '".@mysql_escape_string($this->field_enclose_char). "' ESCAPED BY '".@mysql_escape_string($this->field_escape_char). None of them mention 'error' or appear (to me) to relate to error. I found these using my eyes, but before I start learning how to use my fingers to look, learn what a cursor is, or what delete means, I first need to understand which @ would relate to an error supressor.
  14. Uhm - thanks for the clarification - I thought you might have meant remove it from the fridge !! I did start my query stating
  15. Forgive my lack of knowledge - I'm not sure, where would I remove this '@' from?
×
×
  • 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.