How to create image?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Jasmina

How to create image?

Post by Jasmina »

This is my first post and I hope that you can help me.
I have image generated from flash swf file and saved in "images" folder. This is PHP code for it:

Code: Select all


<?php
error_reporting(0);
/**
 * Get the width and height of the destination image
 * from the POST variables and convert them into
 * integer values
 */
$w = (int)$_POST['width'];
$h = (int)$_POST['height'];
// create the image with desired width and height
$img = imagecreatetruecolor($w, $h);
// now fill the image with blank color


imagefill($img, 0, 0, 0xFFFFFF);
$rows = 0;
$cols = 0;
// now process every POST variable which
// contains a pixel color 
for($rows = 0; $rows < $h; $rows++){
	// convert the string into an array of n elements
	$c_row = explode(",", $_POST['px' . $rows]);
	for($cols = 0; $cols < $w; $cols++){
		// get the single pixel color value
		$value = $c_row[$cols];
		// if value is not empty (empty values are the blank pixels)
		if($value != ""){
			// get the hexadecimal string (must be 6 chars length)
			// so add the missing chars if needed
			$hex = $value;
			while(strlen($hex) < 6){
				$hex = "0" . $hex;
			}
			// convert value from HEX to RGB
			$r = hexdec(substr($hex, 0, 2));
			$g = hexdec(substr($hex, 2, 2));
			$b = hexdec(substr($hex, 4, 2));
			// allocate the new color
			
			$test = imagecolorallocate($img, $r, $g, $b);
			// and paste that color into the image
			// at the correct position
			imagesetpixel($img, $cols, $rows, $test);
		}
	}
}


// save the image
$imagePathName="images/".$_POST['imageName'].".jpg";
imagejpeg($img,$imagePathName , 100);
imagedestroy($img);


?>

I want to use ImageMagick for this but I don't know how.
Thanks.
Post Reply