Jump to content

Image upload script - Border


lokie538

Recommended Posts

Hi,

 

I have a image upload script working, but I want it to automaticly upload a faded border on it. I have a black site and dont want a hard edge on the picture.

 

Im not sure about the way to do it?

 

Maybe make a gif with a transparent middle? Or is there a better way?

 

Well here is my upload script atm:

// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
$uploadedfiletype = $_FILES['uploadfile']['type'];


// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);

imagejpeg($src,"../Gallery/Original/". $newname . ".jpg",100);


// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
$height_orig = $height;
$width_orig = $width;

// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable

// maximum height and width
$width_max = "500";
$height_max = "800";

// initialize reduced dimensions
$heightr = $height_orig;
$widthr = $width_orig;

// if height exceeds max, scale down dimensions
if ($height_max < $heightr) {
$heightr = $height_max;
$widthr = ($height_max / $height_orig) * $width_orig;
}

// if width still exceeds max, further scale down dimensions
if ($width_max < $widthr) {
$heightr = ($width_max / $widthr) * $heightr;
$widthr = $width_max;
}



$tmp = imagecreatetruecolor($widthr, $heightr); 

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $widthr, $heightr, $width_orig, $height_orig); 

// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "../Gallery/Large/". $newname . ".jpg";
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
// has completed.

//echo $width;
//echo "<br>";
//echo $height;
//echo "<br>";

$imagesize= "../Gallery/Large/". $newname . ".jpg";

list($width2,$height2)=getimagesize($imagesize);

//echo $width2;
//echo $height2;


///////////////////////////////// Watermark



$picid = $_GET['picid'];
$imagesource = "../Gallery/Large/" . $newname . ".jpg";
$filename = "../Gallery/Large/" . $newname . ".jpg";
if (!file_exists($imagesource)) die();
$filetype = strtolower(substr($imagesource,strlen($imagesource)-4,4));
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); 
if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); 
if($filetype == ".png") $image = @imagecreatefrompng($imagesource); 
if (empty($image)) die();
$watermark = @imagecreatefromgif('watermark.gif');
$imagewidth = imagesx($image);
$imageheight = imagesy($image); 
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);

if($watermarkwidth > $imagewidth OR $watermarkheight > $imageheight) {

} else {

$startwidth = (($imagewidth - $watermarkwidth - 3) );
$startheight = (($imageheight - $watermarkheight) ); 
imagecopy($image, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
imagejpeg($image,$filename,100);
imagedestroy($image);
imagedestroy($watermark);

Link to comment
Share on other sites

 

can do this but it a example only.

<?php

$img = ImageCreateFromJPEG('img.jpg');

// Draw border
$color_black = ImageColorAllocate($img, 0, 0, 0);
drawBorder($img, $color_black, 3);


// Output
header('Content-type: image/jpeg');
ImageJPEG($img);



// Draw a border
function drawBorder(&$img, &$color, $thickness = 1)
{
    $x1 = 0;
    $y1 = 0;
    $x2 = ImageSX($img) - 1;
    $y2 = ImageSY($img) - 1;

    for($i = 0; $i < $thickness; $i++)
    {
        ImageRectangle($img, $x1++, $y1++, $x2--, $y2--, $color_black);
    }
}

?> 

Link to comment
Share on other sites

Ok what I did was make a border in gif format, so im trying to get it to overlay on top (its transparent in the middle). Ive tried some code but I keep getting errors.

 

<?php

$img = ImageCreateFromJPEG('2.jpg');

$border = ImageCreateFromGIF('border.gif');

list($widthg,$heightg)=getimagesize('border.gif');

$widthj = imagesx($img);
$heightj = imagesy($img);

$tmp = imagecreatetruecolor($widthr, $heightr); 

imagecopyresampled($tmp, $border, 0, 0, 0, 0, $new_widthj, $new_heightj, $widthg, $heightg);

//imagecopy($tmp, $border,  0, 0, 0, 0, $widthj, $widthj);

$filename = "200.jpg";
imagejpeg($border,$filename,100);


?> 

 

Hmm im not to good at the syntax, but I try to load the original picture, then load the border, resize the border so it matches the dimentions of the original picture and then apply the border over the original picture and then save it.

Link to comment
Share on other sites

Ok ive tried new script

 

<?php

$img = ImageCreateFromJPEG('3.jpg');

$border = ImageCreateFromGIF('border.gif');

list($widthg,$heightg)=getimagesize('border.gif');

echo "Widthg: " . $widthg;
echo "<br>heightg: " . $heightg;

$widthj = imagesx($img);
$heightj = imagesy($img);

echo "<br><br>widthj: " . $widthj;
echo "<br>heightj: " . $heightj;

$tempio = imagecreatetruecolor($widthj, $heightj);

imagecopyresampled($tempio, $img, 0, 0, 0, 0, $widthj, $heightj, $widthj, $heightj);

imagecopyresampled($tempio, $border, 0, 0, 0, 0, $widthj, $heightj, $widthg, $heightg);

imagejpeg($tempio,"1000.jpg",100);
?> 

 

But it does not apply the border with transparency.

 

So ive got this as the border:

http://www.lookpic.com/files/border.gif

 

but the fade isnt transparent, when its run through it comes out with this:

http://www.lookpic.com/files/10001.jpg

 

So do you guys know a way to make it fade, as the background of the website if black so im trying to give it a feather / faded background.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.