Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
resize image on upload
Old 09-05-2005, 08:42 PM resize image on upload
Experienced Talker

Posts: 38
Location: Holland
Trades: 0
hey i have a code to resize images on upload.
it works great for all .gif files.

but it just dont want to work for .jpg or .jpeg images, could you maybe see what is wrong?

PHP Code:
    if($filename['name'] != null) {
        if(@
file_exists("images/avatars/".$user_name."".$ext)) {
          
$delete = @unlink("images/avatars/".$user_name."".$ext);
        }
   
        
$dimensions getimagesize($filename['tmp_name']);
        
$aspectRat = (float)($dimensions[1] / $dimensions[0]);

        
$new_max_width 80;
        
$new_max_height 80;

        if((
$dimensions[0] <= $new_max_width) && ($dimensions[1] <= $new_max_width)) {
          
copy($filename['tmp_name'], "images/avatars/".$user_name."".$ext);  
          
$newX $dimensions[0]; 
          
$newY $dimensions[1]; 
        } 
        else { 
          
$width_ratio $dimensions[0] / $new_max_width
          
$height_ratio $dimensions[1] / $new_max_height
       
          if(
$width_ratio >= $height_ratio) {
            
$newY $new_max_width $aspectRat
            
$newX $new_max_width
          } 
          else { 
            
$newY $new_max_height
            
$newX $new_max_height * (1/$aspectRat); 
          } 
       
          
$destImg ImageCreateTrueColor($newX$newY);
          echo 
$dimensions[2];

          if (
$dimensions[2] == 1) { 
            
$sourceImg ImageCreateFromGIF($filename['tmp_name']); 
          } 
          elseif (
$dimensions[2] == 2) { 
            
$sourceImg ImageCreateFromJPEG($filename['tmp_name']); 
          } 
          else 
          { 
            echo 
"This file cannot be used. It is not a jpg, gif<br>"
          } 
          
imagecopyresampled($destImg$sourceImg0000$newX$newY$dimensions[0],  $dimensions[1]); 
          
imagejpeg($destImg"images/avatars/".$user_name."".$ext);

          echo 
"<img src='images/avatars/".$user_name."".$ext."'>";
        }  
      } 
it gives me the message This file cannot be used. It is not a jpg, gif (in the last else function you can see) even if its a .jpg or .jpeg (dont really know the difference).

greets
excalibur112 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-05-2005, 09:13 PM
Experienced Talker

Posts: 38
Location: Holland
Trades: 0
ok i figured out that a lot of images are .pjpeg

you maybe know the function to create an image from that like
ImageCreateFromGIF or so?
excalibur112 is offline
Reply With Quote
View Public Profile
 
Old 09-06-2005, 02:44 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
It doesn't matter what the extension is - if it is a JPEG image, use imageCreateFromJPEG(). A .pjpeg image is just a .jpg image where someone has renamed to have a weird extension.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 09-07-2005, 09:28 AM
Experienced Talker

Posts: 38
Location: Holland
Trades: 0
ok thanx for explanation oberon.

so the code works fine
excalibur112 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to resize image on upload
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61006 seconds with 12 queries