Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Creating an image map for Gdlib generated image

images php coding issues or problems here.

Moderators: macek, egami, gesf

Creating an image map for Gdlib generated image

Postby miabelli » Mon Jan 31, 2005 11:49 pm

Hi!

I´ve made a procedure which generates an image dynamically based on data in a MySQL database. The key point here being, that I have no way of knowing in advance, how the picture will look.

I need to make an image map, which points to some areas in the image.
The problem is, that the image map has to be defined prior to generating the image (at which point i will find out, what areas to map)

Hope this makes sense?

Does anybody have a solution to the problem that the map has to be defined before I know what I want to map?

Regards
Thomas
miabelli
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Jan 31, 2005 11:37 pm

Postby ruturajv » Tue Feb 01, 2005 8:23 pm

but do you know what positions do you have to create the image map... ?
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

http://www.miabelli.dk/categories_and_hits.jpg

Postby miabelli » Tue Feb 01, 2005 8:54 pm

Hi!

This is what I am trying to do:

- I have made a sample OSC (Open Source Commerce) e-shop and populated it with some sample product categories and products.

- From the log-tables I generate this picture with Gdlib:
Image
The picture shows the categories(blue), the products(yelllow) and the number of times each have been shown to users (Hits).

- I wants to map the categories and products so that the user (admin of the site) can click on theese and be taken to the product or category in question.

- Since I have no way of telling which categories, sub-categories and products exists in advance, i do not know the areas, I want to map ind advance.

- I have solved the problem by:
A) calculating the picture once and pickiing up the reference koordinates
B) calculating the picture again, and this time showing it (with the map)
This does however force me to run the procedure twice.

I hope this clarifies the situation.

Regards, Thomas
miabelli
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Jan 31, 2005 11:37 pm

Postby ruturajv » Wed Feb 02, 2005 7:39 pm

- Since I have no way of telling which categories, sub-categories and products exists in advance, i do not know the areas, I want to map ind advance.

If you don't know where they belong then how can you even link those products or categories...
ie. if you know the category they fall... then how can you href category?id=4 something like that... ?
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby miabelli » Wed Feb 02, 2005 8:38 pm

From the page that uses the statistics (graphic) I make the following call:

Code: Select all
echo "<img alt = \"Besøgsstatistik\" src=\"grafik.php\" border = \"0\" usemap = \"#grafikmap\"> ";


the "grafik.php" is where I calculate the positions of the boxes and make the actual drawing,

the pseudo-code of grafik.php is something like:

1: from the database find out which products exist
(here I also get the information about the link i want to use in the map)

2: draw these products to the far right

3: Find out which categories these products belkong to, and draw them to the left of the products

4: Fiinally make the "Imagejpg("created image") call


So I do pick up both the right positions during the drawing and the hrefs during the database callls, but it is too late to use them in the map, because the
Code: Select all
 usemap = \"#grafikmap\"
has to be placed prior to the part where I pick up positions (map koordinates) and the links,

The ideal way to do it, as I see it would be to:

1: Prepare the picture and pick up map koordinates and references in the process

2: now show the picture with the usemap = ....

- But this is not (as far as I have tried) not possible (thus my post)

This is, I´m afraid the best way I can explain it. The core of the problem is the order of which things have to be done.

Thanks for your patience and for trying to help me :)

Regards
Thomas
miabelli
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Jan 31, 2005 11:37 pm

Postby ruturajv » Thu Feb 03, 2005 8:27 pm

ok then I think it is simple....
consider... this...
  • you make a function where you actually calculate the co-ordinates...
  • use that function to create your image
  • in the (html|php) where you display graph...
    Code: Select all
    <map name="..">
    <?php
    include 'function_file.php';
    $values = call_the_function();

    // now echo the co-ordinates
    ?>
    </map>
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby miabelli » Fri Feb 04, 2005 11:17 am

If I understand you correctly, what you suggest I do is:


1) Make function to calculate koordinates
2) (In the same function draw the picture)
3) include the function when the picture is inserted in php

My postulate still is, that this is not feasible whre using the direct stream (ie the picture generated by gdlib is not saved before it is called)

The paradox still remains, that waht i try to accomplish is ultimately a pseudo-code like:

[...insert picture [A: function that calculates and streams picture] using the map [B: koordinates picked up at the same time as A] ]

I have solved the problem by:

1: generate picture and pick up coordinates
2: saved the picture
3: now make the call with reference to the saved picture and the koordinates picked up.

This however requires that the image be saved and then called again, which is time-consuming.


I again thank you for trying to solve the issue, but I´m afraid it is difficult for me to explain the paradox better than I have tried. If you for some reason should have 10 minutes to spare, I dare you (but in no way ask of you) to accomplish the following:

1: make a function that draws a 10x10 pixel box in a 100x100 pixel picture at a random spot.

2: Using _direct streaming_ (no saving) of that picture make an image_map of the 10x10 box so that when the user clicks on the spot he is taken to http://www.google.com

I´m sure, that it can be done, but I have still to figure out how.

Thanks again for the time spent, and If I have totally misunderstood your posts, and you have in fact solved the problem, I apologize :)

Best wishes
Thomas
miabelli
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Jan 31, 2005 11:37 pm

Postby ruturajv » Sun Feb 06, 2005 7:21 pm

1) Make function to calculate koordinates
2) (In the same function draw the picture)
3) include the function when the picture is inserted in php


hi,
the 2nd pt is incorrect... just include the function script, and in another script create all the necessary image manipulations, like colors, borders, etc.

and the script where u generate image...

Code: Select all
<?php
...
include_once 'co-ordinate-calculating-function-only.php';
$img = imagecreate(...);

...
all the processing...
... and finally..

header("Content-Type: image/png");
imagepng($img);
?>


this is the solution where you do not have to save the image anywhere !
Just let me know if ya understand or I'll mail you your code... :D
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to PHP coding => Images

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.