Pixelpost

Authentic Photoblog Flavour


Go Back   Pixelpost Forum > DEVELOPMENT > Hacks and Modifications

Post Reply
 
Thread Tools
  #1  
Old 10-18-2004, 08:27 PM
utok Offline
pp regular
 
Join Date: Oct 2004
Posts: 26
Post Image resize and Wallpapers Mod

Latest update: Applied to the 1.4.3 fix.
Download from pixelpost.org: http://www.pixelpost.org/v1/index.ph...ads&details=64
Download from jondrews.com: http://www.jondrews.com/pixelpost_v1..._mod_utoks.zip

I really liked this script but there were a few things that were somewhat annoying when it came to uploading images. My camera takes large images and often, I'll just want to post the image without doing any modifications in Photoshop or the like.

So I decided that if the pixelpost script resized my images to 600px wide and whatever fit for the height, it would really help me out. After hacking around with the code I got it working. I also added another set of lines that creates wallpaper versions of the image provided that it is larger than 1280x1024. The mod is relativly easy. It cannot be an addon because of the place that it must be executed. An addon could only resize after the fact. Anyhow-->


Download the zip file
http://jondrews.com/pixelpost_v1.4_w..._mod_utoks.zip
EDIT: I updated to 1.4 a while ago-- the mods download section is down so here it is on my page.
Once hte new mod comes out past 1.4.1 I'll do an update. I also plan on figuring out that jhead stuff so it'll keep the exif data on resize.

Here is what I did.

Around line 294-295 and beyond--> this is what I did:
Code:
// prepare the file
	    if($_FILES['userfile'] != "") {
    //utoks mod --> moved $filenamn up so it could be used in resizeimage
			$filnamn = $_FILES['userfile']['name'];
			//end utoks mod
		    $uploadfile = $upload_dir. $_FILES['userfile']['name'];
		        if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
		        //this is utoks' mod --> creates wallpaper
		        // chmod($uploadfile, 644); removed--> resizeimage does the chmod() now. 
		        $imagesize = getimagesize($uploadfile);
		        $imagewidth = $imagesize[0];
		        $imageheight = $imagesize[1];
		        if($imagewidth>=1280){
					createwallpaper(array("file" => $filnamn, "max_width" => "1280", "max_height" => "1280"));
					}
				//end utoks mod
		        //this is utoks' mod --> resizes image(just like createthumbnail)
		        resizeimage(array("file" => $filnamn, "max_width" => "600", "max_height" => "600"));
		        //end utoks mod
			    $result = check_upload($_FILES['userfile']['error']);
			    
				if($headline == "") {
					$headline = $filnamn;
				}
				//utoks mod--> there was $filenamn here-- but i moved it up.
			    $filtyp = $_FILES['userfile']['type'];
			    $filstorlek = $_FILES['userfile']['size'];
			    $status = "ok";
			    } else {



			    // something went wrong, try to describe what
			    echo "Error";
			    $result = check_upload($_FILES['userfile']['error']);
			    echo "<br>$result<hr>";
			    $status = "no";
			    } // end move
		    } // end prepare of file
If you look at the code--> you will notice that it reffers to two different functions: resizeimage() and createwallpaper(). both of these functions are almost exact replicas of the createthumbnail() function that was included in the original code. All I did is change the place that they put the images. I appended them to the end of the script, right after createthumbnail(). Here are both functions:

Code:
function resizeimage($args) {
    // credit to codewalkers.com - this is 99% a tutorial there
    //utoks added this--> only difference is the place it puts the images. 
    $file = $args['file'];
    $max_width = $args['max_width'];
    $max_height = $args['max_height'];
    define(IMAGE_BASE, "../images");
    $image_path = IMAGE_BASE . "/$file";
    $img = null;
    $ext = strtolower(end(explode('.', $image_path)));
  
    if ($ext == 'jpg' || $ext == 'jpeg') {
      $img = @imagecreatefromjpeg($image_path);
        } else if ($ext == 'png') {
        $img = @imagecreatefrompng($image_path);
        } else if ($ext == 'gif') {
        $img = @imagecreatefromgif($image_path);
        }
         
    if($img) {
        $width = imagesx($img);
        $height = imagesy($img);
        $scale = min($max_width/$width, $max_height/$height);
        if($scale < 1) {
            $new_width = floor($scale*$width);
            $new_height = floor($scale*$height);
            $tmp_img = imagecreatetruecolor($new_width,$new_height);
            // gd 2.0.1 or later: imagecopyresampled
            // gd less than 2.0: imagecopyresized
            if(function_exists(imagecopyresampled)) {
                imagecopyresampled($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
                } else {
                imagecopyresized($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
                }
            imagedestroy($img);
            $img = $tmp_img;
            }
        }
  
    imagejpeg($img, "../images/$file");
    $resizedimage = "../images/$file";
    chmod($resizedimage, 0644);
    }
and then createwallpaper()
Code:
 function createwallpaper($args) {
    // credit to codewalkers.com - this is 99% a tutorial there
    //utoks added this--> only difference is the place it puts the wallpaper versions. 
    $file = $args['file'];
    $max_width = $args['max_width'];
    $max_height = $args['max_height'];
    define(IMAGE_BASE, "../images");
    $image_path = IMAGE_BASE . "/$file";
    $img = null;
    $ext = strtolower(end(explode('.', $image_path)));
    if ($ext == 'jpg' || $ext == 'jpeg') {
      $img = @imagecreatefromjpeg($image_path);
        } else if ($ext == 'png') {
        $img = @imagecreatefrompng($image_path);
        } else if ($ext == 'gif') {
        $img = @imagecreatefromgif($image_path);
        }
    if($img) {
        $width = imagesx($img);
        $height = imagesy($img);
        $scale = min($max_width/$width, $max_height/$height);
        if($scale < 1) {
            $new_width = floor($scale*$width);
            $new_height = floor($scale*$height);
            $tmp_img = imagecreatetruecolor($new_width,$new_height);
            // gd 2.0.1 or later: imagecopyresampled
            // gd less than 2.0: imagecopyresized
            if(function_exists(imagecopyresampled)) {
                imagecopyresampled($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
                } else {
                imagecopyresized($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height);
                }
            imagedestroy($img);
            $img = $tmp_img;
            }
        }
    imagejpeg($img, "../images/wallpaper/wall_$file");
    $thumbimage = "../images/wallpaper/wall_$file";
    chmod($thumbimage,0644);
    }
Well, theres my ugly hack of the code. It works well for me. I'm not much of a programmer. Really more of a photographer than a coder. I do realize that much of what I did was probably inefficient and messy to say the least. I wrote it to get a job done, regardless of how it got the job done.

A few things you can change. If you want to change the size of the image when it is resized--> just change the max_width and max_height that you pass into resizeimage()

Code:
resizeimage(array("file" => $filnamn, "max_width" => "600", "max_height" => "600"));
If you wanted 800 wide images then just change it to:
Code:
resizeimage(array("file" => $filnamn, "max_width" => "800", "max_height" => "800"));
Those are the max sizes. It scales the images in relation to their original image. So it won't be making you're beautiful girlfriend fat as hell. ( 8) )

Also--> the same goes for the createwallpaper(). Just change these:
Code:
if($imagewidth>=1280){
	createwallpaper(array("file" => $filnamn, "max_width" => "1280", "max_height" => "1280"));
					}
If you want the wallpapers to be created at 1024width if the image is as large as or bigger than 1024 then just make it:
Code:
if($imagewidth>=1024){
	createwallpaper(array("file" => $filnamn, "max_width" => "1024", "max_height" => "1024"));
					}
Also---> the wallpapers are placed in the images/wallpapers/ directory and are named wall_<thefilename>. So if the filename uploaded was foo.jpg, the wallpaper would be called wall_foo.jpg. In order to link to them you just have to put this in your template:
Code:
<a href="images/wallpaper/wall_<IMAGE_NAME>">wallpaper</a>

Ok-- I think that covers everything. If you have trouble just post here and I'll try and help you out. You could also email me at fjood@inmail.sk

Peace.

Last edited by utok; 11-23-2005 at 12:25 AM.
Reply With Quote
  #2  
Old 10-18-2004, 08:40 PM
pixelpunk's Avatar
pixelpunk Offline
pixelpost guru
 
Join Date: Oct 2004
Location: Sweden
Posts: 504
Send a message via ICQ to pixelpunk
utok, make a .zip file of your entire admin/index.php where these modifications are in place. I think most people will find it easier to just replace their admin script with this one, instead of looking for lines and copy/pasting, which also can create invisible gremlins rendering the file unusable.

cheers // pixelpunk

(you can also create an "developer" account on the front page of pixelpost site, and upload your zipped admin there.
__________________
icq: 66760929
Reply With Quote
  #3  
Old 10-18-2004, 09:05 PM
utok Offline
pp regular
 
Join Date: Oct 2004
Posts: 26
I just posted the modified index.php. I hope it works for the rest of you. I checked it over again just to make sure there were no hardcoding of my directories. I have not tested it on another server so I don't know for sure if it will work in a different environment. But I think it will....
Reply With Quote
  #4  
Old 10-30-2004, 03:04 PM
Olly Offline
forum loafer
 
Join Date: Oct 2004
Location: LasHorgues - France
Posts: 14
Send a message via AIM to Olly
rotate image function

Hi all Pixelpost addicts.

First Thanks Mr PixelPunk for your great piece of software.
As i'm a bit lazzy and really enjoy the utok addon which avoid the use of extra software (from camera right to the pixel post admin).. i develop a small addon to allow the image rotation...(90°CW - 90°CCW - 180°).

But here's my problem : I have changed many things in the admin part... dividing the main file into many (such as functions.php / style.css..) and rewriting the main imageresize function into one for handling thumb, reg size, and wallpapers.

Arghhh... one more thing... i added the option of the regular image size as suggested by Utok... so you can set the image size to 600 or 500...
but this can be done upgrading the config table
One more thing... wallpaper became an option... if checked while posting a new image it will create a wall if not...

so if someone is interested by this add_on... just let me know.
Reply With Quote
  #5  
Old 10-30-2004, 04:07 PM
eugene Offline
forum loafer
 
Join Date: Oct 2004
Posts: 5
Ahh! I am doing the same thing! I just rewrote the whole admin, added a new table and all.... But I am not done, so I would just want your changes!

We should establish a cvs repository or something
Reply With Quote
  #6  
Old 02-10-2005, 07:32 AM
utok Offline
pp regular
 
Join Date: Oct 2004
Posts: 26
I just updated the mod to work on 1.3. It should be working fine now. If you have any problems shoot me an email at jon@jondrews.com. Thanks!

The new version can be located here: http://www.pixelpost.org/index.php?x...&details=4
Reply With Quote
  #7  
Old 02-25-2005, 11:06 AM
shana Offline
forum loafer
 
Join Date: Feb 2005
Location: Japan
Posts: 5
Hello. I installed this modification but it doesn't change the size of my images. Is there something else I need to change in the index before it will work?
You can see what is happening here.

edit: wanted to add that I have just resized the images myself, so you can no longer see what is happening at that link.
I am wondering if it's something I need to change in the template?
__________________
shana
Reply With Quote
  #8  
Old 04-20-2005, 04:33 PM
Anonymous Offline
pixelpost guru
 
Join Date: Oct 2004
Posts: 810
exif

this mod is somewhat useless if it is not retaining EXIF data. It would be as easy as:

create new.jpg
jhead -te original.jpg new.jpg
delete original.jpg

obviously this would add a requirement, but the jhead binary is only one file, and is installed on a lot of systems already. Plus you could just test to see if it exists or not, and if it doesn't don't retain exif data..

jhead is available at http://www.sentex.net/~mwandel/jhead/

just my .02
Reply With Quote
  #9  
Old 06-06-2005, 10:20 PM
utok Offline
pp regular
 
Join Date: Oct 2004
Posts: 26
thats awesome! if ya got the time-- go for it! id really love to see this implemented. Im pressed for time lately so i wont be able to do it-- but if you do get it working-- please send me an email. i would love to have this functioning.
Reply With Quote
  #10  
Old 07-27-2005, 09:12 PM
utok Offline
pp regular
 
Join Date: Oct 2004
Posts: 26
I just updated it to the recent version (1.4.2) it was pretty much just a copy paste. Its working well on my site now.

http://www.pixelpost.org/v1/index.ph...amp;details=64

sidenote: i tried getting hte exif transfer to work with jhead but my server doesnt support exec(). Then i switched over to a library that coppermine uses called phpexifRW but for some reason he says it can write exif data and then in the file itself it says that writing of exif data is temporarily disabled. Do you guys know of another method of transferring the exif data from the original image to the resized image?
Reply With Quote
Post Reply


Thread Tools




All times are GMT. The time now is 06:18 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. | Style Design: d3 designs