PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 28th, 2004, 01:00 PM
Gnosis Gnosis is offline
Sellout
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 215 Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 12 h 38 m 23 sec
Reputation Power: 34
Need GD help - output is gibberish

I need to pull images, resize them, and stick them in place with other html. I'm experienced with php, but not GD...

I've found sample code that seems to do what I need. Almost. When the code is run by itself, it does what it should and outputs the resized image to the browser.

But it only works when the image is the only thing on the page. When I try to embed this code so that the output is in with other output, I get of gibberish data for the image instead of the image.

I suspect this has something to do with the header() bit of the code, but not sure. Please help!

-G
PHP Code:
/* 
    Created by: Matthew Harris 
     ...other notes...
    */ 

    
function thumb($source$scale$quality 80
    { 
        
/* Check for the image's exisitance */ 
        
if (!file_exists($source)) { 
            echo 
'File does not exist!'
        } 
        else { 
            
$size getimagesize($source); // Get the image dimensions and mime type 
            
$w $size[0] / $scale// Width divided 
            
$h $size[1] / $scale// Height divided 
            
$resize imagecreatetruecolor($w$h); // Create a blank image 

            /* Check quality option. If quality is greater than 100, return error */ 
            
if ($quality 100) { 
                echo 
'The maximum quality is 100. <br>Quality changes only affect JPEG images.'
            } 
            else {             
                
header('Content-Type: '.$size['mime']); // Set the mime type for the image 

                
switch ($size['mime']) { 
                    case 
'image/jpeg'
                    
$im imagecreatefromjpeg($source); 
                    
imagecopyresampled($resize$im0000$w$h$size[0], $size[1]); // Resample the original JPEG 
                    
imagejpeg($resize''$quality); // Output the new JPEG 
                    
break; 

                    case 
'image/png'
                    
$im imagecreatefrompng($source); 
                    
imagecopyresampled($resize$im0000$w$h$size[0], $size[1]); // Resample the original PNG 
                    
imagepng($resize''$quality); // Output the new PNG 
                    
break; 
                } 

                
imagedestroy($im); 
            } 
        } 
    }  

$file "school.jpg";
thumb($file10); 

Reply With Quote
  #2  
Old August 28th, 2004, 02:17 PM
replax replax is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Aug 2004
Posts: 1,795 replax User rank is Second Lieutenant (5000 - 10000 Reputation Level)replax User rank is Second Lieutenant (5000 - 10000 Reputation Level)replax User rank is Second Lieutenant (5000 - 10000 Reputation Level)replax User rank is Second Lieutenant (5000 - 10000 Reputation Level)replax User rank is Second Lieutenant (5000 - 10000 Reputation Level)replax User rank is Second Lieutenant (5000 - 10000 Reputation Level)replax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 15 h 23 m 11 sec
Reputation Power: 80
an image is a separate file on the webserver. so if you include image data into a page, it will look like random crap. it must be separate from teh rest of the output.

what you can do is have an external file that just resizes and call it by
<img src='resize.php?filename=image.jpg&width=100&height=100'>
if you put the resize code in resize.php it should work

Reply With Quote
  #3  
Old August 28th, 2004, 03:06 PM
Gnosis Gnosis is offline
Sellout
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 215 Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level)Gnosis User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 12 h 38 m 23 sec
Reputation Power: 34
Quote:
Originally Posted by replax
an image is a separate file on the webserver. so if you include image data into a page, it will look like random crap. it must be separate from teh rest of the output.

what you can do is have an external file that just resizes and call it by
<img src='resize.php?filename=image.jpg&width=100&height=100'>
if you put the resize code in resize.php it should work




Sweeet. Works like a charm. And makes sense to boot! Thanks!

-G

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Need GD help - output is gibberish


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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 7 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek