PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old February 13th, 2004, 04:09 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Help with GD-functions in PHP

Hi!
I've searched for a long time on the net, but I didn't exactly found where I was looking for.
The purpose of my function is to resize an image. That's not the hardest part. But I want the function to automatically change the longest side of the pic.
I.E. User uploads image 1024x768, function resizes it to 800x600
User uploads image 768x1024, function resizes it to 600x800

Is there a way to check which side is the longest?

Reply With Quote
  #2  
Old February 13th, 2004, 07:59 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
There are functions for getting the dimensions of an image (I forget what the precise function is). The quick and dirty way to do this is to get these dimensions and test for which one is bigger. If the x axis is bigger, resize to 800x600; else resize to 600x800.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old February 13th, 2004, 08:19 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Could you provide some code for me? I never used GD before...
[edit]
I figured it out. I now use getimagesize(). But it's not perfect. Suggestions are still welcome!!!
[/edit]
__________________
Work to live, don't live to work

Reply With Quote
  #4  
Old February 13th, 2004, 09:31 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Now I'm trying to add text on a image. I use the function Imagestring() but it doesn't seem to work... Any GD-guru's here who knows how to do this?

I succesfully resized images now and I want a copyright notice on the image in the lower-rightcorner. I've seen a lot of sites using this, but I just don't seem to find the right function... Please help me!!

Reply With Quote
  #5  
Old February 13th, 2004, 10:48 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Perhaps this tutorial will help ya:
http://www.phpfreaks.com/tutorials/105/1.php

Here's a quick example of display text as an image (taken from the tutorial mentioned above):
PHP Code:
<?php
        header 
("Content-type: image/png");
        
$img_handle ImageCreate (23020) or die ("Cannot Create image");
        
$back_color ImageColorAllocate ($img_handle01010);
        
$txt_color ImageColorAllocate ($img_handle233114191);
        
ImageString ($img_handle3155,  "My first Program with GD"$txt_color);
        
ImagePng ($img_handle);
    
?>

Reply With Quote
  #6  
Old February 13th, 2004, 11:14 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Thnx for the tip, but...
I don't want to create a new canvas to put my text on... I want to insert my text on an excisting image. I don't know if it's possible, but I want to make it cross-filetype. So that it will work on GIF, JPEG, PNG etc.

Reply With Quote
  #7  
Old February 13th, 2004, 12:41 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Maybe this code snippet will help. I've pulled it out of the scope of a class, so you'll need to read around all the $thises. Basically, to add text to an existing image, you have to create a bounding box. In this code, I'm also doing a check to make sure the text will fit on the image I'm writing it to (the if block) and dying if it won't. After you've created your bounding box, you allocate a color, and then you just add your text to the image, passing the appropriate coordinates, widths, etc., as documented at php.net. Hope this'll get you started.

PHP Code:
 $box=imagettfbbox($this->fontsize,0,$this->font,$this->copy);
$width=abs($box[2]-$box[0]);
$height=abs($box[3]-$box[1]);
if(
$width > ($this->header_size[0] - 30)){
    die(
"The character width of the string you have provided is too wide.");
}

        
$color=imagecolorallocate($this->image,$this->fontcolor[0],$this->fontcolor[1],$this->fontcolor[2]);
imagettftext($this->image,$this->fontsize,0,($this->copyleft 15 ),  ($this->copytop $this->fontsize 50),$color,$this->font,$this->copy); 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Help with GD-functions in PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway