Rentapatch Patch

Here is a small tutorial to add more functionality to rentapatch which I made a long time ago.

The tutorial should allow you to upload jpeg, png, gif
And over that it will resize the images to fit a full number.

Hope you like, it should work with the latest version. I don’t know if they still release those but here goes…

Here is a small tutorial fix for rentapatch pixel lister so that it auto resize to a 10th rounded number

Below is the code to fix the upload to allow the end-user facility when uploading
Open: upload.php
Find:

$error = ‘Image width and height must be divisable by ten. i.e. 30×80′;

Replace with:

$wi = round($image_dimensions[0]);
$hi = round($image_dimensions[1]);

$wi = $wi/10;
$wi = round($wi);
$wi = $wi*10;

$hi = $hi/10;
$hi = round($hi);
$hi = $hi*10;

if($wi > $cfg['width_limit'] && $wi < 10)
{
$error = ‘Advert too big or small, maximum size of for is ‘.$cfg['width_limit'].’x’.$cfg['height_limit'].”;
}
elseif($hi > $cfg['height_limit'] && $wi < 10)
{
$error = ‘Advert too big or small, maximum size of for is ‘.$cfg['width_limit'].’x’.$cfg['height_limit'].”;

}
else
{
//lets continue

move_uploaded_file($_FILES['image']['tmp_name'], $cfg['upload_path'].$upload_file);
$src=null;

if ($file_extension == “jpg”) {
// Create new image from JPG
$src = imagecreatefromjpeg($cfg['upload_path'].$upload_file);
}
elseif ($file_extension == “png”) {

// Create new image from GIF
$src = imagecreatefrompng($cfg['upload_path'].$upload_file);
}
elseif ($file_extension == “gif”) {

// Create new image from GIF
$src = imagecreatefromgif($cfg['upload_path'].$upload_file);
}

$thumb = @imagecreatetruecolor( $wi, $hi );
@imagecopyresampled($thumb, $src, 0, 0, 0, 0, $wi, $hi, $image_dimensions[0], $image_dimensions[1] );

$new_image = substr($upload_file,0,-3).’.jpg’;
imagejpeg($thumb,$cfg['upload_path'].$new_image,$cfg['jpg_quality']);

@unlink($cfg['upload_path'].$upload_file);
$_SESSION['sess_image'] = $new_image;
$_SESSION['sess_width'] = $wi;
$_SESSION['sess_height'] = $hi;

$src=null;
}

Now to allow png images to be uploaded

Open: upload.php
Find:

$allowed_extensions = array(“gif”,”jpg”,”GIF”,”JPG”);

Replace with:

$allowed_extensions = array(“gif”,”jpg”,”GIF”,”JPG”, “png”, “PNG”);

Open: libraries/function.lib.php
Find:

if ($ext == “jpg”) {
// Create new image from JPG
$src = imagecreatefromjpeg($cfg['upload_path'].$image);
}

Add Below:

elseif ($ext == “png”) {

// Create new image from GIF
$src = imagecreatefrompng($cfg['upload_path'].$image);
}

Here is the finished files:

files



Leave a Reply