Pixelpost Forum

Pixelpost Forum (http://www.pixelpost.org/forum/index.php)
-   Hacks and Modifications (http://www.pixelpost.org/forum/forumdisplay.php?f=16)
-   -   Another auto resize hack (http://www.pixelpost.org/forum/showthread.php?t=1464)

romain 07-08-2005 01:34 PM

Another auto resize hack
 
Hi,
here is the hack for PixelPost V1.4.1 i have done for my site so as to avoid using an image editor tool to resize the pix before uploading it.
It allows resizing the width or height of the image with parameters set in the options panel.

INSTALL:
Download the zip file from http://dominica.et.romain.free.fr/AutoResizeImage.zip

Unzip it at the root of your PixelPost site. It will override admin/index.php and admin/options.php files. Upload them with your FTP client.

If you have changed the prefix of the pixelpost tables, you have to edit the name og the config table (by default pixelpost_config). Run the script with your Mysql admin tool (Most of the time, PHPMyAdmin)

HOW TO USE IT:
In the options panel, a new part is added : AUTO RESIZING OF UPLOADED IMAGES

http://dominica.et.romain.free.fr/resizeoptions.jpg

You can activate the hack (by default, no).
You can set the max limit your image shall have (by default 600 pixels, either width or height), and the compression rate for JPG pix (by default 80% - this rate is used to compress the picture. The smaller this rate is, the lightest your image is but the poorer the quality is).

Once configured, just upload images as usual with New Image.

HOW IT WORKS:
When you upload an image, the hack checks if the width or height are bigger than the configured size limit. If yes, then the resize function is called.
The longest side of the image is resized according to the limit,
the other side is resized according to the image ratio.

MODIFIED LINES:
admin/options.php
lines 72-92 : resize options form

admin/index.php
lines 420-434 : main call to the resizeImage function.
lines 871-873 : treatment of the options.php form, storage of the parameters into the config table
lines 1050-1122 : resizeImage function


DEVELOPMENT NOTES:
It might be interesting to set different values to limit width and height.
I haven't thought yet of such a feature as the longest side is enough for me for the moment. But i guess that it should go through a double treatment width and then height.


I hope you will enjoy.
Romain

raminia 07-08-2005 03:31 PM

is EXIF data intact or it will be gone?

(in the next release you can do this with an addon not a mod)

raminia 07-08-2005 04:52 PM

Try this toolbox for putting back the EXIF info:
http://www.ozhiker.com/electronics/pjmt/

suggesting:
1 - read exif info from the original file.
2 - resize the file
3 - read the header information of the resized file
4 - put the original EXIF into the new header of the resized file
5 - put the modified header information of the resized file back into it.

romain 07-08-2005 05:14 PM

To be honest, i don't know, as i don't use the EXIF data from my camera.
After tests on my images, i can retrieve the exif data related to FILE and COMPUTED formats. Thx to tell me if all the data are saved.

I am pretty sure that imagecopyresampled, the GD function i use to resize resets the EXIF data related to cam. For me, it is not an issue. Before that, i was resizing my pix with ACDSee and the metadata were lost while editing.

I know how to retrieve the EXIF data from a picture with GD, i don't know how to insert data into a picture. If such a method exists, then, the exif data retrieved before the resizing can be reinjected after resizing. It is a way to solve this.

romain 07-08-2005 05:16 PM

Thx raminia, i gonna try.

raminia 07-08-2005 08:38 PM

I've done this with http://www.vinayras.com/projects/phpexifrw/phpExifDocs/ but the written EXIF info is not valid. ACDsee underestand it but EXIFER and my other exif program does not recognize it. It seems the imagecopyresampled has added some additional comments that exif programs does not like them or something else;)

romain 07-11-2005 10:49 AM

EXIF Info reinjected into the JPEG
 
I have used the PHP JPEG Metadata Toolkit as suggested by Raminia.
The EXIF information from the original JPEG picture, ie before resizing it, is reinjected into the resized picture.
This injection is limited to JPEG and EXIF data. I do not reinject the comments or origina intrisic data.

New zip including the autoresize modifications and the pjmt toolkit delivery can be found here :
http://dominica.et.romain.free.fr/Au...injectEXIF.zip
To install, unzip as is into admin folder.
Run the SQL script with your mySQL admin tool.

Hacks :
Index.php is modified :

Line 40 Calls to needed libraries from pjmt
Code:

// Call PHP JPEG Metadata  Toolkit library
require('pjmt/JPEG.php');
require('pjmt/EXIF.php');

Line 1125: Retrieve of the EXIF data of the original JPEG
Code:

$original_exif_data = get_EXIF_JPEG( $file );
Lines 1166: Reinjection of the original EXIF data into the resized picture:
Code:

$resized_jpeg_header = get_jpeg_header_data($resizedpath);
// Alter the EXIF data of the resized pix
$resized_jpeg_header = put_EXIF_JPEG( $original_exif_data, $resized_jpeg_header);
if ( FALSE == put_jpeg_header_data( $resizedpath, $resizedpath, $resized_jpeg_header ) ) {
  // Writing of the new file didn't work - output error message
  echo "Error - Failure to write new JPEG : $resizedpath <br>\n";
}

Once your image resized and downloaded, you can check the injected data with a new link included in index.php :
http://dominica.et.romain.free.fr/ne...rExifCheck.jpg
This opens a popup with pjmt/getMetaData.php file (some light modifications from Example.php provided with the toolkit)
http://dominica.et.romain.free.fr/getMetaData.jpg

raminia 07-11-2005 11:46 AM

wow!
I'll make an admin addon from it for the next release with preserving your credits!!

That's great! thanks!

raminia 07-11-2005 11:51 AM

Quote:

Originally Posted by raminia
I've done this with http://www.vinayras.com/projects/phpexifrw/phpExifDocs/ but the written EXIF info is not valid. ACDsee underestand it but EXIFER and my other exif program does not recognize it. It seems the imagecopyresampled has added some additional comments that exif programs does not like them or something else;)

btw, this mod has to many php files. It may be more than whole default php files of pp. The http://www.vinayras.com/projects/phpexifrw/phpExifDocs/ I used was very simple and small but the EXIF was not valid. I opened the file with Photoshop ans 'saved as' a new file and the exif become valid! I think the way phpexifrw does it could be fixed. Meanwhile to re-inject the EXIF info there is no need to have the whole makernotes (I think). Maybe some of the files are redundant. I'll check it at home.

Thanks again.

romain 07-11-2005 12:05 PM

For sure the number of files can be optimized, and even the number of lines. I took the delivery from toolkit as is, with no modifications.
Yet, as I used the toolkit only to retrieve JPG header and EXIF specific functions, many of the other functions are useless (jfif, photoshop, ...).


All times are GMT. The time now is 01:00 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.