PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Oct 18, 2018 8:45 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: thumb script
PostPosted: Mon Sep 13, 2004 7:53 pm 
Offline
Forum Newbie

Joined: Mon Sep 13, 2004 7:47 pm
Posts: 1
feyd | Please use
Syntax: [ Download ] [ Hide ]
tags when posting code. Read:  <a href="http://forums.devnetwork.net/viewtopic.php?t=21171" class="postlink">Posting Code in the Forums</a></span>





Hello. I have searched the thumbnail scripts and threads here and haven't found anything to point me in the right direction yet. I am having GREAT difficulties getting this script to work. THe full sized image upload is working... the thumbnail is NOT AT ALL. Any help would be greatly appreciated.

Right now the line:
Syntax: [ Download ] [ Hide ]
$src_img=imagecreatefromjpeg($fullNameThumb);

Returns 4 errors. All stemming from the fact that it is not finding the file/path associated with $fullNameThumb. If I substitute $fullName for $fullNameThumb, there are no erros reported but the thumb script produces nothing.
I tried using the normal copy function with $fullNameThumb (you'll see it commented out) to try and create the image for temporary use in the thumb script... No luck.
I have checked and the GD library is installed and the proper version too, phpinfo();
here is the entire script thus far:
Syntax: [ Download ] [ Hide ]
if (@$file) {

        //declare var for photo file name for db

        $photo_file = $file['name'];

        //sql

        $query = "    INSERT into photos (photo_file, photo_date, photo_desc)

                    VALUES ('$photo_file', '$date', '$desc')"
;

        $result = mysql_query($query, $conn) or die(mysql_error());

         

         

        //path name vars

        $abspath = $HTTP_SERVER_VARS['PATH_TRANSLATED'];

        $stub=ereg_replace("/photoAdd.php","/",$abspath);

     

        // use $fullname for the resulting path for file uploads, based on any changes you make above

        $fullname = $stub ."/images/photos/".$file['name'];

        $fullNameThumb = $stub ."/images/photos/thumbs/".$file['name'];

         

      //copies full sized image

        copy($file['tmp_name'],$fullname);

        //copy($file['tmp_name'],$fullNameThumb);

         

        //begin thumbnail script

        $src_img=imagecreatefromjpeg($fullNameThumb);  

        $old_x=imagesx($src_img);  

        $old_y=imagesy($src_img);  

        $thumb_w=50;

        $thumb_h=50;

        $dst_img = imagecreatetruecolor($thumb_w,$thumb_h);  

        //echo $src_img;

         imagecopyresampled($dst_img,$src_img,0,0,0,0,$th

umb_w,$thumb_h,$old_x,$old_y);  

        //imagedestroy($dst_img);

        //imagedestroy($src_img);

    }


Thanks in advance for any help.
1M.


feyd | Please use
Syntax: [ Download ] [ Hide ]
tags when posting code. Read:  <a href="http://forums.devnetwork.net/viewtopic.php?t=21171" class="postlink">Posting Code in the Forums</a></span>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 8:14 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
Moved to Graphics.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 3:20 pm 
Offline
Forum Newbie
User avatar

Joined: Sun Nov 28, 2004 11:58 am
Posts: 12
Location: Netherlands
Make 2 files:

file 1 (html, call it what ever u want):
Syntax: [ Download ] [ Hide ]
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;body&gt;
&lt;form enctype="multipart/form-data" method="post" action="uploadandresize.php"&gt;
  &lt;p&gt;
    Bestand:
    &lt;input type="file" name="userfile"&gt;
&lt;/p&gt;
  &lt;p&gt;
    Doelmap:
    &lt;input type="text" name="doelmap"&gt;
&lt;/p&gt;
  &lt;p&gt;
    Betandsnaam:
      &lt;input type="text" name="bestandsnaam"&gt;
&lt;/p&gt;
  &lt;p&gt;
    &lt;input type="submit" name="Submit" value="uploaden"&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/body&gt;
&lt;/html&gt;


File 2 (call it uploadandresize.php)
Syntax: [ Download ] [ Hide ]
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
Bestand: &lt;? echo $userfile; ?&gt;&lt;br&gt;
Bestands naam: &lt;? echo $userfile_name; ?&gt;&lt;br&gt;
Bestands grote: &lt;? echo $userfile_size; ?&gt;&lt;br&gt;
Bestands type: &lt;? echo $userfile_type; ?&gt;&lt;br&gt;
&lt;br&gt;
Doelmap: &lt;? echo $doelmap; ?&gt;&lt;br&gt;
Nieuwe bestands naam: &lt;? echo $bestandsnaam; ?&gt;&lt;br&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;?php
// look if file with same name allready exists
&lt;?php
// resize to thumbnail script
$width = 200;
$height = 200;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($userfile);

if ($width &amp;&amp; ($width_orig &lt; $height_orig)) &#123;
  $width = ($height / $height_orig) * $width_orig;
&#125; else &#123;
  $height = ($width / $width_orig) * $height_orig;
&#125;
// Resample
// if GD 2.0.l or greater is available use imagecreatetruecolor() instead of imagecreate()
$image_p = imagecreate($width, $height);
$image = imagecreatefromjpeg($userfile);
// if GD 2.0.l or greater is available use imagecopyresampled() instead of imagecopyresized()
imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// save resized picture in desination folder
imagejpeg($image_p, $doelmap."/thumb".$bestandsnaam, 85);
?&gt;

&lt;?php
// save uploaded picture in destination folder
if (rename($userfile,$doelmap."/".$bestandsnaam)==true)&#123;
        echo "Bestand is met succes geupload&lt;br&gt;";
&#125; else &#123;
        echo "Er is een fout opgetreden bij het uploaden van het bestand&lt;br&gt;";
&#125;
?&gt;
&lt;/body&gt;
&lt;/html&gt;


IMPORTANT make sure u upload to a folder u have permission for!!


Sorry that part of the code's in dutch...........
Any way the code should upload both the original and the thumbnail.
The thumbnail will look crap unless u use GDlib 2.0.1 or higher and use imagecopyresampled() instead of imagecopyresized() and imagecreatetruecolor() instead of imagecreate().

Hope it helps


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 5:06 pm 
Offline
DevNet Resident

Joined: Sun Jul 20, 2003 9:25 pm
Posts: 1150
Location: West Yorkshire, England
Check out my file upload class in the code snippet section as it does all that you want.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 4:23 am 
Offline
DevNet Resident
User avatar

Joined: Wed Oct 09, 2002 6:51 pm
Posts: 1206
Location: Keele, U.K.
echo out
Syntax: [ Download ] [ Hide ]
<?php

$fullname = $stub ."/images/photos/".$file['name'];

$fullNameThumb = $stub ."/images/photos/thumbs/".$file['name'];

?>


what are there values are they pointing to the right directories that you want?

you also appear to be missing saving the file add
Syntax: [ Download ] [ Hide ]
<?php

imageJpeg($dst_img, $fullNameThumb);

?>


after your imagecopyresamples().
http://uk.php.net/manual/en/function.imagejpeg.php


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group