Forum Moderators: coopster

Message Too Old, No Replies

Enlarge image canvas or joining two images with php

         

Seregwethrin

12:30 pm on May 24, 2008 (gmt 0)

10+ Year Member



Hello friends;

<snip>

I can't do that thing. I don't want to resize the whole image. I just want to resize canvas.

I think it could be like this;

$im = imagecreatefromjpeg ( 'test.jpg' );
$width = imagesx($im);
$height = imagesy($im);
$canvas = imagecreatetruecolor($width, $height + 15);

Maybe i can join them. But i can't find the functions.

Anyone can help me by that way? Or any other ways to do this?

[edited by: Seregwethrin at 12:32 pm (utc) on May 24, 2008]

[edited by: dreamcatcher at 1:40 pm (utc) on May 24, 2008]
[edit reason] No urls please! [/edit]

Seregwethrin

12:44 pm on May 24, 2008 (gmt 0)

10+ Year Member



Thanks for reading, I've done it with imagecopy().

Marcia

1:02 pm on May 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to try to do this, (and then put a border around the whole image/canvas using CSS). Could you post the code you used to do it? Thanks. :)

Seregwethrin

1:29 pm on May 24, 2008 (gmt 0)

10+ Year Member



That's my function, from my upload class. You can edit and adapt your code. It makes a border around image and writes "WidthxHeight xyzkb" like imageshack thumbnails. :)

function drow_thumb ()
{
if ( $this->img['thumbnail'] == '1' )
{
if ( $this->img['realext'] == 'jpg' )
$im = imagecreatefromjpeg ( $this->img['thumbpath'] );
elseif ( $this->img['realext'] == 'gif' )
$im = imagecreatefromgif ( $this->img['thumbpath'] );
elseif ( $this->img['realext'] == 'png' )
$im = imagecreatefrompng ( $this->img['thumbpath'] );

$thumbW = imagesx ( $im );
$thumbH = imagesy ( $im );

$canvas = imagecreatetruecolor($thumbW, $thumbH + 15);

imagecopy ( $canvas , $im , 0 , 0 , 0 , 0 , $thumbW, $thumbH );

imagedestroy ( $im );

$thumbH += 15;

$white = imagecolorallocate($canvas, 255, 255, 255);
$black = imagecolorallocate($canvas, 0, 0, 0);

imagefilledrectangle ( $canvas , 0 , $thumbH - 15 , $thumbW , $thumbH , $black );
imagerectangle ( $canvas , 0 , 0 , $thumbW - 1 , $thumbH - 1 , $black );

if ( $this->img['size'] < 1024 )
$imghsize = $this->img['size'] . 'b';
elseif ( $this->img['size'] < 1024*1024 )
$imghsize = intval ( $this->img['size'] / 1024 ) . 'kb';
elseif ( $this->img['size'] >= 1024*1024 )
$imghsize = intval ( $this->img['size'] / 1024 / 1024 ) . 'mb';

$text = $this->img['width'] . 'x' . $this->img['height'] . ' ' . $imghsize;

$textwidth = ceil ( '6' * strlen ( $text ) );
$lefttextspace = intval ( ( $thumbW - $textwidth ) / 2 );

if ( $textwidth >= $thumbW )
{
$text = $imghsize;
$textwidth = ceil ( '6' * strlen ( $text ) );
$lefttextspace = intval ( ( $thumbW - $textwidth ) / 2 );
}

imagestring ( $canvas , 2 , $lefttextspace , $thumbH - 14, $text , $white );

if ( $this->img['realext'] == 'jpg' )
imagejpeg ( $canvas , $this->img['thumbpath'] );
elseif ( $this->img['realext'] == 'gif' )
imagegif ( $canvas , $this->img['thumbpath'] );
else
imagepng ( $canvas , $this->img['thumbpath'] );

imagedestroy ( $canvas );

}

$this->insert_into_sql();
}

[edited by: Seregwethrin at 1:31 pm (utc) on May 24, 2008]