Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1280 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Rending Images into a circle - GD

Thread title: Rending Images into a circle - GD
Reply    
    Thread tools Search this thread Display Modes  
02-24-2011, 07:41 PM
#1
dlcoding is offline dlcoding
Status: I'm new around here
Join date: Nov 2010
Location: Exmouth
Expertise: Software And Web Development
Software: Dreamweaver, Visual Studio
 
Posts: 6
iTrader: 0 / 0%
 

dlcoding is on a distinguished road

  Old  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
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

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?

Reply With Quote
02-24-2011, 08:36 PM
#3
dlcoding is offline dlcoding
Status: I'm new around here
Join date: Nov 2010
Location: Exmouth
Expertise: Software And Web Development
Software: Dreamweaver, Visual Studio
 
Posts: 6
iTrader: 0 / 0%
 

dlcoding is on a distinguished road

  Old

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

Reply With Quote
02-24-2011, 09:24 PM
#4
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

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.

Thanked by:
dlcoding (02-25-2011)
02-24-2011, 09:33 PM
#5
Eightloop is offline Eightloop
Eightloop's Avatar
Status: Member
Join date: Jan 2011
Location:
Expertise: Programming, photography
Software: Notepad++, Photoshop
 
Posts: 112
iTrader: 0 / 0%
 

Eightloop is an unknown quantity at this point

  Old

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

Thanked by:
dlcoding (02-25-2011)
02-25-2011, 12:29 AM
#6
dlcoding is offline dlcoding
Status: I'm new around here
Join date: Nov 2010
Location: Exmouth
Expertise: Software And Web Development
Software: Dreamweaver, Visual Studio
 
Posts: 6
iTrader: 0 / 0%
 

dlcoding is on a distinguished road

  Old

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!

Reply With Quote
02-25-2011, 12:57 AM
#7
Eightloop is offline Eightloop
Eightloop's Avatar
Status: Member
Join date: Jan 2011
Location:
Expertise: Programming, photography
Software: Notepad++, Photoshop
 
Posts: 112
iTrader: 0 / 0%
 

Eightloop is an unknown quantity at this point

  Old

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.

Reply With Quote
Thanked by:
dlcoding (02-25-2011)
02-25-2011, 01:46 AM
#8
dlcoding is offline dlcoding
Status: I'm new around here
Join date: Nov 2010
Location: Exmouth
Expertise: Software And Web Development
Software: Dreamweaver, Visual Studio
 
Posts: 6
iTrader: 0 / 0%
 

dlcoding is on a distinguished road

  Old

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(2525);

$image imagecreate($Imgwidth$Imgheight) or die("Failed to create stream");
$bgcolor imagecolorallocate($image255255255);

 
  
 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
 
$distdeg2rad(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($image000);
    
imagecopy($image$image2
              ((
cos($deg)*$radius)+$centerPoint[0])-($imageSizes[0]/2) ,
              ((
sin($deg)*$radius)+$centerPoint[1])-($imageSizes[1]/2) ,
              
00imagesx($image2), imagesy($image2));
    
    
imagesetpixel($image, (cos($deg)*$radius)+$centerPoint[0], (sin($deg)*$radius)+$centerPoint[1], imagecolorallocate($image25500));
   
 }

imagepng($image);
imagedestroy($image);

?>

Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed