Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author nickboss

    (@nickboss)

    Hi, the plugin uses WordPress native functions (GD library) to resize images and create thumbnails. Unfortunately these functions do not keep EXIF data. It can be done with another library called ImageMagick, but your web server needs to support it. Here is a relative article about it.

    Thread Starter cargarm3

    (@cargarm3)

    Yes,in my server ImageMagick is installed. How could I make a hook so that, before the image is upload I could check the EXIF information? Once I have this information, your plugin uploads the image (using GD) and later I would rotate that image using the EXIF information of the “original” image.

    Thank you.

    Plugin Author nickboss

    (@nickboss)

    At the article I sent you at the bottom it says about a plugin, ImageMagick Engine, which is supposed to replace the native GD library of WordPress when editing images. You can try it out. It should normally do the work, though it hasn’t been updated for years.

    Thread Starter cargarm3

    (@cargarm3)

    Yes, I tried and modified all, but did not work. I Think that the only solution would be using the line:

    $eexif = exif_read_data(‘image.jpg’);

    before resizing the image so that the EXIF information would not be deleted… but I don’t know how can I have access to that “image.jpg”in your code… I suppose with a hook or modifying the source code.

    Can you help me?

    Plugin Author nickboss

    (@nickboss)

    When performing upload the plugin will preserve the original file. If you have enabled medialink attribute, so that files are added to the Media library of your WordPress website, then additional image sizes are added to the library (thumbnails), using the native WordPress functions.

    The code that adds the image files to the Media library and creates the thumbnails (which loose EXIF information) is found in function wfu_process_media_insert at wfu_functions.php inside /lib folder of the plugin’s directory.

    Reasonably speaking, I expect that the original image has kept EXIF information, but smaller sizes of it no.

    Thread Starter cargarm3

    (@cargarm3)

    No way, it doesn’t work. I try to put these code lines in wfu_process_media_insert:

    	$exif = exif_read_data($file_path);
    	$file = fopen("./wp-content/plugins/wordpress-file-upload-pro/lib/test.txt", "w");
    	fwrite($file, "This is a new text line" . PHP_EOL);
    	fwrite($file, $file_path . PHP_EOL);
    	fwrite($file, $exif . PHP_EOL);
    	fclose($file);

    And the file is not created, I mean, the code does not execute this function. If I put these lines in file wordpress_file_upload (in folder wordpress-file-upload-pro) creates the test file, but in that file I don’t know where Can I extract the exif information of the path.

    Plugin Author nickboss

    (@nickboss)

    ok, try to create a hook and implement wfu_after_upload filter. This filter runs after all files have been uploaded. The code should look like this:

    
    if (!function_exists('wfu_after_upload_handler')) {
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    		foreach ( $additional_data["files"] as $file ) {
    			$file_path = $file["filepath"];
    			$exif = exif_read_data($file_path);
    			$txtpath = WP_CONTENT_DIR.'/test.txt';  //this is the same as ./wp-content/test.txt
    			if ( $txtfile = fopen($txtpath, "w") ) {
    				fwrite($txtfile, "This is a new text line" . PHP_EOL);
    				fwrite($txtfile, $file_path . PHP_EOL);
    				fwrite($txtfile, $exif . PHP_EOL);
    				fclose($txtfile);
    			}
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }
    

    I haven’t tested it but it should work.

    Nickolas

    Thread Starter cargarm3

    (@cargarm3)

    I’ve tried it, but it does not write any file. Also, I’ve tried “debugging” it like :

    echo “Test1”;

    if (!function_exists('wfu_after_upload_handler')) {
    echo "Test2";
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    echo "Test3";
    		foreach ( $additional_data["files"] as $file ) {
    echo "Test4";
    			$file_path = $file["filepath"];
    			$exif = exif_read_data($file_path);
    			$txtpath = WP_CONTENT_DIR.'/test.txt';  //this is the same as ./wp-content/test.txt
    			if ( $txtfile = fopen($txtpath, "w") ) {
    				fwrite($txtfile, "This is a new text line" . PHP_EOL);
    				fwrite($txtfile, $file_path . PHP_EOL);
    				fwrite($txtfile, $exif . PHP_EOL);
    				fclose($txtfile);
    			}
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }

    But only Test1 and Test 2 are printed. ??

    Plugin Author nickboss

    (@nickboss)

    it is natural not to see Test3 and Test4, because the output is not echoed to the screen, you should try this instead:

    
    if (!function_exists('wfu_after_upload_handler')) {
    echo "Test2";
    	function wfu_after_upload_handler($changable_data, $additional_data) {
    wfu_debug_log("Test3");
    		foreach ( $additional_data["files"] as $file ) {
    wfu_debug_log("Test4");
    			$file_path = $file["filepath"];
    			$exif = exif_read_data($file_path);
    			$txtpath = WP_CONTENT_DIR.'/test.txt';  //this is the same as ./wp-content/test.txt
    			if ( $txtfile = fopen($txtpath, "w") ) {
    				fwrite($txtfile, "This is a new text line" . PHP_EOL);
    				fwrite($txtfile, $file_path . PHP_EOL);
    				fwrite($txtfile, $exif . PHP_EOL);
    				fclose($txtfile);
    			}
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
    }
    

    This will output Test3 and Test4 in a file called debug_log.txt inside /wp-content directory. After you make the upload check if that files exists and contains this output. Then we proceed.

    Nickolas

    Thread Starter cargarm3

    (@cargarm3)

    I’ve tested this code :

    if (!function_exists("wfu_after_upload_handler")) {
    	wfu_debug_log("Test4");
    	function wfu_after_upload_handler($changable_data, $additional_data){
    		wfu_debug_log("Test5");
    		foreach($additional_data["files"] as $file ) {
    			wfu_debug_log("Test6");
    			$file_path = $file["filepath"];
    		}
    		return $changable_data;
    	}
    	add_filter("wfu_after_upload","wfu_after_upload_handler",10,1);
    }

    and uploaded an image (image uploaded OK), but the file debug_log.txt only contains this:
    Test4Test4Test4Test4Test4Test4Test4Test4Test4Test4Test4Test4

    I mean, wfu_after_upload_handler never is executed (and as I said before, image is loaded ok).

    Plugin Author nickboss

    (@nickboss)

    the handler takes 2 parameters, so what if you set

    
    add_filter("wfu_after_upload","wfu_after_upload_handler",10,2);
    

    does it make any difference?

    Thread Starter cargarm3

    (@cargarm3)

    What I have done is changing the event wu_after_upload for this one :

    if (!function_exists(‘wfu_after_file_loaded_handler’)) {
    function wfu_after_file_loaded_handler($changable_data, $additional_data) {
    ….

    }
    }

    Now I can extract my Exif info and rotate the image according the EXIF information.

    Plugin Author nickboss

    (@nickboss)

    ok this is good also

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Keep EXIF Information / Image Upload rotation’ is closed to new replies.