473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Create image from url: multiple problems

Thew
69
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['img']) && is_numeric($_GET['img'])){ 
  3. $img = $_GET['img']; 
  4.  
  5. $imgarray = array ( 
  6. '1' => 'http://www.path/to/image1.png', 
  7. '2' => 'http://www.path/to/image2.png', 
  8. '3' => 'http://www.path/to/image3.png'
  9. );
  10.  
  11. $src = $imgarray[$img];
  12. header('Content-type: image/png');
  13. echo file_get_contents($src);
  14. }
  15. else
  16. {
  17.     header('Content-type: image/png');
  18. echo 'Image could not be loaded';
  19. }
  20. ?>
Hello again bytes! Im having multiple problems. 1: When the $_GET['img'] is set and its numeric, the image will be displayed right, but i want to add text in the upper-right corner of the image... How can i do that? I've looked through multiple GD tutorials and examples but i can't find my answer. 2: When $_GET['img'] isn't set i want to display the text: Image could not be loaded. How cna i do that? Because this doesn't seem to work...
Dec 25 '10 #1
4 2875
Dormilich
8,658 Expert Mod 8TB
in both cases you need to apply imagecreatefromstring() or a combination of this with other GD functions. mind that you have to return an image, not text.
Dec 25 '10 #2
johny10151981
1,059 1GB
think simple:

you dont need to print the content of the image by yourslef.

you can do this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['img']) && is_numeric($_GET['img'])){ 
  3. $img = $_GET['img']; 
  4.  
  5. $imgarray = array ( 
  6. '1' => 'http://www.path/to/image1.png', 
  7. '2' => 'http://www.path/to/image2.png', 
  8. '3' => 'http://www.path/to/image3.png'
  9. );
  10.  
  11. $src = $imgarray[$img];
  12. echo "<img src='".$src."' alt='".$src."'>";
  13. }
  14. else
  15. {
  16.  echo 'Image could not be loaded';
  17. }
  18. ?>
  19.  
if a specific file is missing and you want to print some text then you must not set the Content-type. just print the missing message.
Dec 25 '10 #3
Dormilich
8,658 Expert Mod 8TB
although that code has to be put in the HTML page …
Dec 25 '10 #4
Thew
69
I searched on PHP.net and after some time i found this:

Expand|Select|Wrap|Line Numbers
  1. $text = base64_decode('Image could not be loaded!');
  2.  
  3.     $im = imagecreatefromstring($text);
  4.     header('Content-Type: image/png');
  5.     imagepng($im);
  6.     imagedestroy($im);
But that doesn't seem to work at me? And the text in the upper-right corner? How can i do that?
EDIT: I searched through the GD Functions and imagestring() worked. But now i still want to place my text in the upper-right corner when $_GET['img'] is set...
Dec 25 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: waz | last post by:
Hi please can someone help me on how to create image with asp ?
2
by: Mark Kamoski | last post by:
How can one change an image url at runtime? (Note, the image exists in a user control.) This is the image tag on the ascx... <asp:image id="TopBanner" runat="server"></asp:image> ....but...
2
by: jdi | last post by:
Hello, I have a seemingly basic question about ASP.NET. I would like to create a page containing an image, which keeps swapping the url of the image source, without refreshing the entire page. ...
1
by: blarfoc | last post by:
I am using the ImageButton to represent tabs on my webform. I have 5 tabs. Each tab can have 2 images. A clicked imaagge and a unclicked image. When I click on a image that is not clicked I...
2
by: TAM | last post by:
Hi Sorry for posting in the wrong newsgroup but posting with the hope that someone will answer. I was wondering if anyone can tell me if I can create image map in Visual Studio .Net? I know it...
1
by: Ken Yu | last post by:
Hi, How can create image in ListView and ComboBox ? tks a lot ! Ken
5
by: Nalaka | last post by:
Hi, When an image is put on a master page... the url to th eimage is set relatve to the master page. (at least don't know how top set an absolute URL to image) But the when a content page is...
3
by: Kiran A K | last post by:
Hi, I have an image url (eg:http://myimages.com/pic1.jpg) Now i want to display the above image in a C# windows form. Which control should i use? i am using VS .NET 2003. Pls provide some...
2
by: rockdale | last post by:
I believe this must be a very sample question. I have a image dir under myWebsite (myWebSite is the root dir of my web appl) I have an ascx file under myWebsite/userControls in the c# of...
6
by: dr | last post by:
does anyone see what is wrong with my .gif download logic? no matter what image url i try it downloads a junk file that can't be opened in any paint program. System.Net.WebRequest myRequest =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.