Changing an Image Dynamically

by 13 replies
16
I want to change the image that is displayed on another site based on the number of completed sales for a product (basically I want to create my own "WSO Pro" buttons since WSO Pro has been having trouble lately.

What I want to do is have the buy button image that appears on the forum automatically change as the sales go up. I am thinking this means I create multiple buttons and, based on a parameter on my site, the same image name serves up the "right" image based on sales.

How do I serve a different image based on number of sales on a remote site?
#programming #changing #dynamically #image
  • First off, you will need a way of tracking sales. I recommend via database if that's possible...

    If you can use database, then this is how:

    - Create database
    - Create a table named "sales"
    - Create two fields named "id" and "count". Make the value of id = 1.

    ^Sales will need to be updated on each sale (don't know what system your using).

    Attached is a basic script to get your desired effect for images. But again, you will need a way to count downloads in a database.


    ^ I just wrote this off the top of my head, so haven't double checked code
    • [ 1 ] Thanks
    • [1] reply
    • OK, I will make an assumption, and hopefully point you in the right direction.

      I am assuming that you will be placing a static image link on an external website from where your images are held (e.g. static image link on WSO, linking to your image on your own webserver).

      Example link on WSO:-

      <img src="http://somewebsite.com/my_wso_button.php">

      On your server, the my_wso_button.php script will need to do the following:-

      1) Determine how many sales have been made (probably using a database to count)
      2) Depending upon number of sales, the script will select the appropriate image, and send the image.

      For this, you will need to create your actual images, and save them on the server. Then, the my_wso_button.php script will use the order count, and redirect to the correct image.

      Your my_wso_button.php will contain something like this:-

      if ($count < 10)
      header("Location: http://www.your-domain.com/buy_17.gif");
      elseif ($count < 20)
      header("Location: http://www.your-domain.com/buy_27.gif");
      else
      header("Location: http://www.your-domain.com/buy_37.gif");

      This should do what you need.
      • [ 1 ] Thanks
      • [1] reply
  • Thanks nzjav05. That would work with images on my own site.

    Unfortunately, that's not what I want. I needed to be more clear.

    I want this to work in such a way that the image tag is located on the Warrior Forum, not on my site, so I want the dynamic image that is served to actually have the same file name as the previous image.

    So here's what it would look like...

    In the forum post would be an image location that looks like this:

    http://www.myurl.com/images/buybutton.png


    The "buybutton.png" file would be changed to reflect the number of sales/price point.
    • [1] reply
    • What you want to do is not put the number IN the image of the button. Just have a blank button png, and update its value.

      You would get the number of sales in php then ...

      HTML Code:
      <input type="button" value="<?php echo   ?>" style="background: transparent url(http://www.myurl.com/images/buybutton.png);">
      • [ 1 ] Thanks
      • [1] reply
  • hey there Kevin

    what you need to do is:

    1. build your db table to store data
    2. update that data when sales occur
    3. create a script that reads that data
    4. have this script output that data as an png or jpg image using GD
    5. insert an image tag into your posts here, using the script as the source

    here is a link to some code you can review as an framework to help you build your own script:

    http://www.ilikenetwork.com/nifty/display_sales.phps

    peace
    • [ 2 ] Thanks
    • [2] replies
    • This is EXACTLY what I needed. You are TEH AWESOME.
    • Yup, this is the way to do it ... dont expect it to look good though i personally think GD looks like crap ..

      plus .. you have to have GD turned on in your server
  • update

    i like the solution from (jminkler) as well.. it would eliminate the need to create an image, and you can just output text from the script. an easy modification.

    i think i'll use it myself

    peace
  • i'm using firefox and was able to see the image from the test page. ff 3.6
    • [ 1 ] Thanks
    • [1] reply
    • I use a browser check to see if it displays for them. I still can't get it to display for me (I have FF 3.6 running as well--I've disabled grease monkey, etc.)
      • [1] reply

Next Topics on Trending Feed

  • 16

    I want to change the image that is displayed on another site based on the number of completed sales for a product (basically I want to create my own "WSO Pro" buttons since WSO Pro has been having trouble lately. What I want to do is have the buy button image that appears on the forum automatically change as the sales go up. I am thinking this means I create multiple buttons and, based on a parameter on my site, the same image name serves up the "right" image based on sales.