How do you store what's in the cart? A session variable? Hidden form elements? URL encoded ID's?
Depending on which your code will differ hugely at this stage, but ultimately you're looking to do the same thing, which is to get a count of items and assign it to an integer variable (we'll call it $num here).
The second stage is using this integer variable to select or generate the image. If you're limiting yourself to ten such images, you could simply pre-prepare ten such images and use a naming convention for them (such as img_X.png, where X is the number). Then it becomes a case of:
$imageName = "img_".$num.".png";
And you can then echo it accordingly in an image element.
Dynamically generating such images is relatively easy using the GD library
, as Art_Wolf suggested. A simple example would be that you call your image generating script as if it were an image
, and this in turn would generate the image and output it with the correct content-type:
$o_Img = imagecreate(50, 15);
$bg = imagecolorallocate($o_Img, 255, 255, 255);
$textcolor = imagecolorallocate($o_Img, 255, 0, 0);
imagestring($o_Img, 5, 0, 0, $num, $textcolor);
That's all there is to it, but as I said first how you keep track of the basket is important, because that is how you get your value for $num in the first place.
What are you using for the basket? A third party script? If so, you might want to Google how it does it, examine the code and/or print to the buffer what it is storing in the session.