TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Centering the x and y ratio in images (http://www.talkphp.com/general/2463-centering-x-y-ratio-images.html)

Orc 03-12-2008 01:38 AM

Centering the x and y ratio in images
 
I want to be able to figure out how to center images, by their x, y ratios using imagecopyresampled. How would I do this?

Rendair 03-12-2008 10:39 AM

One way you can find the center point of an image is to find the width and height and divide by 2

PHP Code:

$size getimagesize($filename);
$width $size[0];
$height $size[1];

$x $width 2;
$y $height 2

Thats the way i have always done it anyway


You can always look at something like this

PHP Code:

// The file
$filename 'test.jpg';
$percent 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width$height) = getimagesize($filename);
$new_width $width $percent;
$new_height $height $percent;

// Resample
$image_p imagecreatetruecolor($new_width$new_height);
$image imagecreatefromjpeg($filename);
imagecopyresampled($image_p$image0000$new_width$new_height$width$height);

// Output
imagejpeg($image_pnull100); 


Gareth 03-12-2008 02:04 PM

There you have it, from the resident GD guru himself! x

Wildhoney 03-12-2008 03:04 PM

Lol :-) Rendair loves his GD, doesn't he.

Orc 03-12-2008 04:43 PM

$_GET['w'] and $_GET['h'] are defined xD
plus my images are from db


All times are GMT. The time now is 11:15 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0