incorporate thumbnail class in existing image upload script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

incorporate thumbnail class in existing image upload script

Post by mesz »

Code: Select all

<?php
$img = new ImageMagick($_FILES[file_form]); 
$img->setTargetdir('whereever'); 
$img->Resize(100,100); 
$img->Save(); 
$img->CleanUp();
?>
How do I incorporate the above code for thumbnail creation via image magick into my existing image upload script?

Code: Select all

<?php
<?php 
$imagesdir = "./images/"; 
if (isset($_FILES['f1'])) { 
  if (!move_uploaded_file($_FILES['f1']['tmp_name'], $imagesdir . $_FILES['f1']['name'])) { 
    echo ' error '; 
  } else { 
  echo ' good upload ';
  } 
} else { 
echo'file uploads';
}
?>
?>
Using this form

Code: Select all

&lt;form action="&lt;?php echo $_SERVER&#1111;'PHP_SELF']; ?&gt;" enctype="multipart/form-data" method="post"&gt; 
         &lt;p&gt; 
            &lt;input type="file" class="form" name="f1" /&gt;&lt;br&gt;
&lt;br&gt;
            &lt;input type="submit" class="button" value="Send the file"/&gt; 
         &lt;/p&gt; 
      &lt;/form&gt;
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

if i am not mistaken you will need to use a system command to access imageMagick functions...

system("convert -geometry 150 $source $destination");
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

xisle wrote:if i am not mistaken you will need to use a system command to access imageMagick functions...

system("convert -geometry 150 $source $destination");
This system command is all new to me.
Thanks for the response, I have a lot more work to do here obviously...
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

I used this code:

Code: Select all

<?php
<?php 
$imagesdir = "./images/"; 
if (isset($_FILES['f1']) && $_FILES['f1']['size'] > 0) { 
  $bigImage = $imagesdir . $_FILES['f1']['name'];
 if (!move_uploaded_file($_FILES['f1']['tmp_name'], $bigImage)) { 
    echo ' error '; 
  } else { 
  echo ' good upload '; 
  } 
  $img = new ImageMagick($bigImage);
$img->setTargetdir('./thumbs');
$img->Resize(100,100);
$img->Save();
$img->CleanUp();
} 
if (isset($_FILES['f1'])) { 
  if (!move_uploaded_file($_FILES['f1']['tmp_name'], $imagesdir . $_FILES['f1']['name'])) { 
    echo ' error '; 
  } else { 
  echo ' good upload ';
 } 
} else { 
;
}
?>
?>
but got this ERROR:

Code: Select all

good upload 
Fatal error: Cannot instantiate non-existent class: imagemagick in /home/.sites/14/site467/web/pic/f2.php on line 15
and nothing was written to ./thumbs

Why is it a non-existent class?
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

I use a system command to access the ImageMagick application on a Linux install. The ImageMagick class would not exist unless you have written it or installed classes for ImageMagick. That is why the error says the class does not exist.

Maybe you just need to include the class file from some libraries you have downloaded? Sorry don't have much info to go on here..
mesz wrote:
$img = new ImageMagick($bigImage);
$img->setTargetdir('./thumbs');
$img->Resize(100,100);
$img->Save();
$img->CleanUp();
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

I know he original question I posted was so vague as to be untrue.
At the time I posted it I really didn't even know what Image Magick or GD library were.
I needed an image gallery in a rush so I have not had time to battle creating one myself - I have instead downloaded a script.
( I cannot think of the URL at the moment, but if anybody reading this wants to know, just ask and I will look it up ).
However I have learnt enough in the process of trying to create an image gallery that I will now do it at my leisure.
Cheers for your input.
Post Reply