View Single Post
Old 04-10-2009, 02:20 AM   #6 (permalink)
scottco
The Visitor
 
Join Date: Apr 2009
Location: Colorado
Posts: 3
Thanks: 0
scottco is on a distinguished road
Default

So, I got this working and furthermore, managed to include rand to generate a random image:

PHP Code:
<?php
//Generate random number
$random rand(117);

//////Begin Image Analysis/////

/* The original image is the average colors */
$average = new Imagick'images/backgrounds/' $random '.png');
 
/* Reduce the amount of colors to 10 */
$average->quantizeImage10Imagick::COLORSPACE_RGB0falsefalse );
 
/* Only save one pixel of each color */
$average->uniqueImageColors();
 
/* Clone the average and modulate to brighter */
$bright $average->clone();
$bright->modulateImage 125200100 );
 
/* Clone the average and modulate to darker */
$dark $average->clone();
$dark->modulateImage 80100100 );
 
/* Helper function to create the mini-images */
function createImagesImagick $compositeImagick $im )
{
    
/* Get ImagickPixelIterator */
    
$it $im->getPixelIterator();
   
    
/* Reset the iterator to begin */
    
$it->resetIterator();
 
    
/* Loop trough rows */
    
while( $row $it->getNextIteratorRow() )
    {
        
/* Loop trough columns */
        
foreach ( $row as $pixel )
        {      
            
/* Create a new image which contains the color */
            
$composite->newImage2020$pixel );
            
$composite->borderImage( new ImagickPixel"black" ), 1);
        }
    }
}
/* This object holds the color images */
$composite = new Imagick();
 
/* Create "icons" for each palette */
createImages$composite$dark );
createImages$composite$average );
createImages$composite$bright );
 
/* Montage the color images into single image
   Ten images per row, three rows */
$montage $composite->montageImage( new imagickdraw(), "10x3+0+0",
                                      
"20x20+4+3>"imagick::MONTAGEMODE_UNFRAME,
                                      
"0x0+3+3" );
 
/* Free some resources */
$composite->destroy();
 
/* Create an empty canvas */
$canvas = new Imagick();
$canvas->newImage$montage->getImageWidth() + 55,
                   
$montage->getImageHeight(),
                   new 
ImagickPixel"white" ) );
 
/* Display the canvas as png */
$canvas->setImageFormat"png" );
 
/* Set font size to 12 points */
$draw = new ImagickDraw();
$draw->setFontSize12 );
 
/* Create legends for each palette */
$canvas->annotateImage$draw5200"Dark: " );
$canvas->annotateImage$draw5450"Average: " );
$canvas->annotateImage$draw5700"Bright: " );
 
/* Composite the montaged images next to texts */
$canvas->compositeImage$montageImagick::COMPOSITE_OVER55);

/* Output the image */
header"Content-Type: image/png" );
echo 
$canvas;
?>
What I can't figure out how to do is then turn around and echo out the actual image or even just some text in addition to the png palette that's created, i.e.:
PHP Code:
echo '<h1>Random is:[' $random ']</h1>'
The purpose for all of this is to generate a palette of colors that I can then select from for font and background colors in the associated stylesheet. Is there a reason I can't have multiple echo statements?

Thanks!
-C.
scottco is offline  
Reply With Quote