Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Converting Images
December 27, 2008, 5:43 pm
rate this thread
Re: Converting Images
<Sat, 27 Dec 2008 09:43:04 -0800 (PST)>
Using the (new resized image) dimentions , Create a new image thats
slightly larger than the (new resized image) and flood fill it with any
colour you want .
Then paste the (new resized image) into it - and save .
top left width = top left width + 2
top left height = top left height +2
When you paste the (new resized image) into the new slightly larger
Re: Converting Images
the syntax wrong somewhere. The original resizing and saving of the
image before imagecopy worked OK.
An image is uploaded and dimensions calculated to a new width of 450.
$imagepath = $imagename; //Sets imagepath to be the uploaded image
$save = "upload/L_" . $imagepath; //Renames the file for saving with
prefix 'L' for large
$file = "upload/" . $imagepath; //The original path
list($width, $height) = getimagesize($file) ;//Retrieves current image
$modwidth = 450; //Sets new width to be 450
$diff = $width / $modwidth;
$modheight = $height / $diff; //Works out new height
A second image is created 8mm larger in height and width, with a
$w = $modwidth+8; //Sets new width
$h = $modheight+8; //Sets new height
$backimage = imagecreate($w, $h); //Creates new image $backimage
$blue = imagecolorallocate($backimage, 51, 153, 204); //Sets colour
imagefilledrectangle($backimage,0,0,$w,$h,$blue); //Fills $backimage
So far so good.... Now to resize the original image to 450 width
$tn = imagecreatetruecolor($modwidth, $modheight) ; //creates new
image with new width and height
$image = imagecreatefromjpeg($file) ;
$imagemod = imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth,
$modheight, $width, $height);
And finally to copy the resized original image onto the large filled
image at coordinates 4,4 to create a filled border effect. Its here
that I keep getting error messages that the supplied argument for
imagejpg and imagecopy are wrong.
$imagenew = imagecopy($backimage, $imagemod, 4, 4, 0, 0, $modwidth,
imagejpeg($imagenew, $save, 100) ;
Thanks in advance