|
|
|
|
Thread title: Rending Images into a circle - GD |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
02-24-2011, 07:41 PM
|
#1
|
Status: I'm new around here
Join date: Nov 2010
Location: Exmouth
Expertise: Software And Web Development
Software: Dreamweaver, Visual Studio
Posts: 6
|
Rending Images into a circle - GD
Okay, this is hard to explain, however, im sure there is a mathematical word for doing it, and calculating it.
I have an array of images, like so:
PHP Code:
$images = {"img1.jpg","img2.jpg","img3.jpg"};
etc.
Now, I need to use GD library to render these in a circle. (As in each image is rendered around, next to each other, in a circle shape)
It must render the images in a circle and if there are more images, it renders them closer together.
Any help on this would be great!
Thanks
|
|
02-24-2011, 08:30 PM
|
#2
|
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
Posts: 6,894
|
Is the desired product supposed to look like a doughnut (a band with a hole in the middle) or a full circle and each image would be like a pizza slice?
|
|
02-24-2011, 08:36 PM
|
#3
|
Status: I'm new around here
Join date: Nov 2010
Location: Exmouth
Expertise: Software And Web Development
Software: Dreamweaver, Visual Studio
Posts: 6
|
Neither..
Something like that, the more images, the closer around the circle they become, and the smaller they become.
Its pretty complicated i know, but any advice on where to start will be greatly appreciated.
Cheers
|
|
02-24-2011, 09:24 PM
|
#4
|
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
Posts: 6,894
|
This would have been easier if you had asked me last year when I actually remembered trig. Basically what you need to do then is put the center of each image along a circle. If you don't know any trig this might be difficult.
First we need to see how far apart each image will be from eachother. To get that it would be dist=6.28/count radians. So if you have five images each one would be separated by 1.256 radians. My trig is too rusty to remember how to actually calculate the distance on the circle from that.
Once you have the x,y position of each image there isn't much from there. All you need to do to center them is move the image half its height and half its width so it is centered. The angle you will have to move it at will vary by where it is at on the circle but can be found as well. Once again I dont remember enough trig.
|
|
02-24-2011, 09:33 PM
|
#5
|
Status: Member
Join date: Jan 2011
Location:
Expertise: Programming, photography
Software: Notepad++, Photoshop
Posts: 112
|
I believe the mathematical word you're searching is trigonometry. You can calculate each position by choosing a constant distance between each image (so the circle gets smaller with fewer images), then calculate the regular polynomial with n borders; n being the total number of images.
Then calculate the radius of the circle and distribute them equally on the circle using trigonometry.
EDIT: VG was faster
|
|
02-25-2011, 12:29 AM
|
#6
|
Status: I'm new around here
Join date: Nov 2010
Location: Exmouth
Expertise: Software And Web Development
Software: Dreamweaver, Visual Studio
Posts: 6
|
Okay guys, its been years since I did Trig in college, but yes, it rings a bell.at least I know what to look for now.
Thanks for help guys. You've been great!
|
|
02-25-2011, 12:57 AM
|
#7
|
Status: Member
Join date: Jan 2011
Location:
Expertise: Programming, photography
Software: Notepad++, Photoshop
Posts: 112
|
I just re-read what you posted, I thought that the size of your circle should be variable and not the size of the images.
This makes it a lot easier then. Ignore my post and follow the advice of GV.
|
|
02-25-2011, 01:46 AM
|
#8
|
Status: I'm new around here
Join date: Nov 2010
Location: Exmouth
Expertise: Software And Web Development
Software: Dreamweaver, Visual Studio
Posts: 6
|
I've pretty much got it done after a few google searches on Trig. If any of you are interested, here is the basis of my code:
PHP Code:
<?php
header("Content-type: image/png");
// main image size
$Imgwidth = 540;
$Imgheight = 540;
//options
$render_circle = false;
// circle size
$centerPoint = array(260,260);
$radius = 200;
// number of images to distribute
$count = 30;
// default size for images
$imageSizes = array(25, 25);
$image = imagecreate($Imgwidth, $Imgheight) or die("Failed to create stream");
$bgcolor = imagecolorallocate($image, 255, 255, 255);
if ($render_circle)
{
// Render circle
for ($i=0; $i < 360; $i++)
{
$degInRad = deg2rad($i);
imagesetpixel($image, (cos($degInRad)*$radius)+$centerPoint[0], (sin($degInRad)*$radius)+$centerPoint[1], $color);
}
}
// calculate points
$dist= deg2rad(6.28/$count);
for ($n=0; $n < $count; $n++)
{
$deg = rad2deg($dist * $n);
$image2 = imagecreate($imageSizes[0],$imageSizes[1]) or die("Failed to create stream");
$bgcolor = imagecolorallocate($image, 0, 0, 0);
imagecopy($image, $image2,
((cos($deg)*$radius)+$centerPoint[0])-($imageSizes[0]/2) ,
((sin($deg)*$radius)+$centerPoint[1])-($imageSizes[1]/2) ,
0, 0, imagesx($image2), imagesy($image2));
imagesetpixel($image, (cos($deg)*$radius)+$centerPoint[0], (sin($deg)*$radius)+$centerPoint[1], imagecolorallocate($image, 255, 0, 0));
}
imagepng($image);
imagedestroy($image);
?>
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|