Jump to content

Image Drawing Help!


phpdude888

Recommended Posts

Hey all, first post here and looking for some help.

 

Background:

 

I am working as a developer for a company.  We are kicking around some new ideas for encryption.  They had a previous (fairly ingeneious) modle of how to procede but it never got off the drawing board.  Basically they would take a message fragment (read cipher text), and pixelate it.  By breaking each letter of the string down to its ascii number and then using sets of threes as color input to create a pixel on screen.  For each set of three characters message you would get a unique pixel.  Interesting idea none the less I seem to have run into some problems.  I am using the GD library to draw the pixels.  I would like to draw the pixels inside of a loop, as we get each componet (red,green,blue) and then apply the new color and draw the image (of course updating the x,y) coordinates as we go.  The problem is that only the first image is drawn, and none after.  Any and all help is appreciated

 

Code follows:

 

Quick note: As a test string I took a random quote from Einstein.

 

<?php

header("Content-type: image/png"); //Set for image

$string = "Quantum mechanics is certainly imposing. But an inner voice tells me that it is not yet the real thing. The theory says a lot, but does not really bring us any closer to the secret of the Old One. I, at any rate, am convinced that He does not throw dice"; //Test string

 

$len=strlen($string); //Get length of string

$c=0; //Loop counter

$red=0; //Color componets

$green=0;

$blue=0;

$count=0; //Counter for colors

$x1cord=0; //Cartesisan coordinates

$y1cord=0;

$x2cord=5;

$y2cord=5;

 

$im = imagecreatetruecolor(500, 500);

for ($c=0; $c<$len; $c++)

{

if($count==0)

{

$red=ord($string[$c]);

$count++;

}

elseif ($count==1)

{

$green=ord($string[$c]);

$count++;

}

 

elseif ($count==2)

{

$blue= ord($string[$c]);

$hue= imagecolorallocate($im, $red, $green, $blue);

imagefilledrectangle($im, $x1cord, $y1cord, $x2cord, $y2cord, $hue);

imagepng($im);

imagedestroy($im);

$red=0; //reset to 0 incase there are componets left over at end of message (not divisible by 3)

$green=0;

$blue=0;

$count=0;

$x1cord=$x1cord+5; //update coordinates

$x2cord=$x2cord+5;

}

}

?>

 

End Code

 

For the coordinates I am assuming that (0,0) is the top left

 

so it maps this way

 

(0,0) (5,5) (First square)

(5,0) (10,5) (Second square)

(x1+5,y1) (x2+5,y2) (ECT)

 

-Matthew

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.