Hi, I have a website, and I allow people to upload images to the site, and then produce a computer photo gallery. You can see it here: http://www.oc-zone.com/phptonuke.php?filnavn=Zone/Galeria/galeria.php

The problem, is that I have to make manual thumbnails, of 100x100.

However, i know I can put ImageMagick to do this, but how? Could you explain me please? It would help me a lot, because it takes a lot of time resizing the images to 100x100 🙁

Thankx for the help! 😉

    Thank you for the reply non_zero

    Now, how can I include this class in the webpage?

    And also, need help on setting these variables:

    var $targetdir= '';
    var $temp_dir
    = '/var/tmp'; // httpd must be able to write there
    var $file_history= array();
    var $temp_file
    = '';
    var $count= 0;
    var $image_data
    = array();
    var $error= '';
    var $verbose
    = FALSE;

    I don´t know what they mean and in which format should they be assigned 🙁

      I really have to insert this in the site, and right now I´m stuck in the variables. 🙁

        I don't know about image magic classes , but what I do in this case is create a thumbnail when the image is first uploaded.

        You want to use imagecopyresized();

          Now, how can I include this class in the webpage?

          put the class file in the directory of your page and use require_once("imagemagick_class.phps") (or the filename u use).
          Then do it like in the example given by non_zero:

          $img = new ImageMagick($_FILES[file_form]);
          $img->setTargetdir('whereever');
          $img->Resize(100,100);
          $img->Save();
          $img->CleanUp();

          There's no need to alter the class file, so do not manipulate the variables u mentioned... they r elements of the class which r used internally.
          hth

            Ok, now I tried to do It, and it goes like this:

            I have two files, one called enviar.php, which has the forms and the access to de database, and includes the files process.php. The process.php is the file that sends all the info to the database. I made it like this:

            <?php
            require_once("imagick_class.php");
            include("global.inc.php");
            $errors=0;
            $error="Ocorreram os seguintes erros enquanto processávamos o seu formulário:<ul>";
            pt_register('POST','Nome');
            pt_register('POST','Projecto');
            pt_register('POST','Zona');
            pt_register('POST','Modelo');
            pt_register('POST','Alteracoes');
            $Alteracoes=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Alteracoes);pt_register('POST','Outros');
            $Outros=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Outros);pt_register('POST','Score');
            pt_register('POST','Activar');
            $Imagem1=$HTTP_POST_FILES['Imagem1'];
            $Imagem2=$HTTP_POST_FILES['Imagem2'];
            $Imagem3=$HTTP_POST_FILES['Imagem3'];
            $Imagem4=$HTTP_POST_FILES['Imagem4'];
            $Imagem5=$HTTP_POST_FILES['Imagem5'];
            $Imagem6=$HTTP_POST_FILES['Imagem6'];
            if($Nome=="" || $Modelo=="" || $Alteracoes=="" || $Imagem1=="" ){
            $errors=1;
            $error.="<li>Não preencheu um ou mais campos obrigatórios.";
            }
            if(!is_uploaded_file($HTTP_POST_FILES['Imagem1']['tmp_name'])){
            $error.="<li>A 1ª imagem, ".$HTTP_POST_FILES['Imagem1']['name'].", não foi enviada!";
            $errors=1;
            }
            if(!is_uploaded_file($HTTP_POST_FILES['Imagem2']['tmp_name'])){
            $image_list[8].="nenhuma.jpg";
            $errors=0;
            }
            if(!is_uploaded_file($HTTP_POST_FILES['Imagem3']['tmp_name'])){
            $error.="<li>A 3ª imagem, ".$HTTP_POST_FILES['Imagem3']['name'].", não foi enviada!";
            $errors=0;
            }
            if(!is_uploaded_file($HTTP_POST_FILES['Imagem4']['tmp_name'])){
            $error.="<li>A 4ª imagem, ".$HTTP_POST_FILES['Imagem4']['name'].", não foi enviada!";
            $errors=0;
            }
            if(!is_uploaded_file($HTTP_POST_FILES['Imagem5']['tmp_name'])){
            $error.="<li>A 5ª imagem, ".$HTTP_POST_FILES['Imagem5']['name'].", não foi enviada!";
            $errors=0;
            }
            if(!is_uploaded_file($HTTP_POST_FILES['Imagem6']['tmp_name'])){
            $error.="<li>A 6ª imagem, ".$HTTP_POST_FILES['Imagem6']['name'].", não foi enviada!";
            $errors=0;
            }
            if($errors==1) echo $error;
            else{
            $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem1']['name'];
            $image_list[8] = $image_part;
            copy($HTTP_POST_FILES['Imagem1']['tmp_name'], "fotos/".$image_part);
            $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem2']['name'];
            $image_list[9] = $image_part;
            copy($HTTP_POST_FILES['Imagem2']['tmp_name'], "fotos/".$image_part);
            $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem3']['name'];
            $image_list[10] = $image_part;
            copy($HTTP_POST_FILES['Imagem3']['tmp_name'], "fotos/".$image_part);
            $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem4']['name'];
            $image_list[11] = $image_part;
            copy($HTTP_POST_FILES['Imagem4']['tmp_name'], "fotos/".$image_part);
            $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem5']['name'];
            $image_list[12] = $image_part;
            copy($HTTP_POST_FILES['Imagem5']['tmp_name'], "fotos/".$image_part);
            $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem6']['name'];
            $image_list[13] = $image_part;
            copy($HTTP_POST_FILES['Imagem6']['tmp_name'], "fotos/".$image_part);
            $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
            $message="Nome: ".$Nome."
            Projecto: ".$Projecto."
            Zona: ".$Zona."
            Modelo: ".$Modelo."
            Alteracoes: ".$Alteracoes."
            Outros: ".$Outros."
            Score: ".$Score."
            Activar: ".$Activar."
            Imagem 1: ".$where_form_is."fotos/".$image_list[8]."
            Imagem 2: ".$where_form_is."fotos/".$image_list[9]."
            Imagem 3: ".$where_form_is."fotos/".$image_list[10]."
            Imagem 4: ".$where_form_is."fotos/".$image_list[11]."
            Imagem 5: ".$where_form_is."fotos/".$image_list[12]."
            Imagem 6: ".$where_form_is."fotos/".$image_list[13]."
            ";
            $link = mysql_connect("localhost","oc-zone","password");
            mysql_select_db("oczone_modding",$link);
            $query="insert into galeria (nome,projecto,zona,modelo,alteracoes,outros,score,activar,imagem1,imagem2,imagem3,imagem4,imagem5,imagem6) values ('".$Nome."','".$Projecto."','".$Zona."','".$Modelo."','".$Alteracoes."','".$Outros."','".$Score."','".$Activar."','".$image_list[8]."','".$image_list[9]."','".$image_list[10]."','".$image_list[11]."','".$image_list[12]."','".$image_list[13]."')";
            mysql_query($query);
            header("Refresh: 0;url=http://www.oc-zone.com");
            }
            ?>

            I haven´t inserted the part of the $img variables yet, as you told me, and I receive the following error:

            Warning: Cannot modify header information - headers already sent by (output started at /home/oc-zone/public_html/Zone/Galeria/imagick_class.php:617) in /home/oc-zone/public_html/Zone/Galeria/process.php on line 88

            From what I understand, this must be the class file saying it could not modify the information, because it has already been sent to the database. So, where should I put those variables?

            And I can´t understand what both this variables do:

            This one, should I change anything?
            $img = new ImageMagick($_FILES[file_form]);

            And this one, should I insert the location where thumbnails (in wherever) should go, like /Zone/Galeria/Thumbnails/ ?
            $img->setTargetdir('whereever');

            You can see the page right here -> http://www.oc-zone.com/phptonuke.php?filnavn=Zone/Galeria/enviar.php

            Thankx for all the help! 😉

              7 days later

              Please, tell me just what to do, ok? Thsi is because right now, I have to make things manually, which takes a lot of time. This would really help!

              Thankx.

                8 days later

                sorry it took some time, i was on vac...
                ok, i guess you stored the imagick_class.php by copyin it from the browser and pastin it to the file... i assume u also copied some whitespaces at the end of the code after the ?> - completely remove em and your error should disappear...
                This is just sample code:
                $img = new ImageMagick($_FILES[file_form]);
                The parameter must be an uploaded file, e.g. $Imagem1 etc.

                And this one, should I insert the location where thumbnails (in wherever) should go, like /Zone/Galeria/Thumbnails/ ?
                $img->setTargetdir('whereever');

                Yes, u should.
                hth

                  Ok, took out the spaces, and now things are sent correctly, but I still don´t have the thumbnails, because I didn´t set those variables yet.

                  Help me understand them:

                  So, the final name the image gets, seems to be .$image_list[8]. , .$image_list[9]. , .$image_list[10]. , .$image_list[11]. , .$image_list[12]. and .$image_list[13].

                  how should i change these variables to represent them?

                  $img = new ImageMagick($_FILES[file_form]);
                  $img->setTargetdir('whereever');
                  $img->Resize(100,100);
                  $img->Save();
                  $img->CleanUp();

                  The target dir must be -> /Zone/Galeria/Thumbnails/

                  The thumbnail name must be the same as the image name.

                  Also, where shoul I put them? (Could you look at the code above, to see how it looks?)

                  Thank you for all the help.

                    Create one object for each file u have:
                    $img = new ImageMagick($Imagem1);
                    and so on....

                    The target dir must be -> /Zone/Galeria/Thumbnails/

                    Do it like this:
                    $img->setTargetdir('/Zone/Galeria/Thumbnails/ r');
                    hth

                      Ok, did it like you said, and I receive the following error:

                      Imagemagick: Upload Failed

                      Here is how I inserted the code:

                      <?php
                      require_once("imagick_class.php");
                      include("global.inc.php");
                      $errors=0;
                      $error="Ocorreram os seguintes erros enquanto processávamos o seu formulário:<ul>";
                      pt_register('POST','Nome');
                      pt_register('POST','Projecto');
                      pt_register('POST','Zona');
                      pt_register('POST','Modelo');
                      pt_register('POST','Alteracoes');
                      $Alteracoes=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Alteracoes);pt_register('POST','Outros');
                      $Outros=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Outros);pt_register('POST','Score');
                      pt_register('POST','Activar');
                      $Imagem1=$HTTP_POST_FILES['Imagem1'];
                      $Imagem2=$HTTP_POST_FILES['Imagem2'];
                      $Imagem3=$HTTP_POST_FILES['Imagem3'];
                      $Imagem4=$HTTP_POST_FILES['Imagem4'];
                      $Imagem5=$HTTP_POST_FILES['Imagem5'];
                      $Imagem6=$HTTP_POST_FILES['Imagem6'];
                      if($Nome=="" || $Modelo=="" || $Alteracoes=="" || $Imagem1=="" ){
                      $errors=1;
                      $error.="<li>Não preencheu um ou mais campos obrigatórios.";
                      }
                      if(!is_uploaded_file($HTTP_POST_FILES['Imagem1']['tmp_name'])){
                      $error.="<li>A 1ª imagem, ".$HTTP_POST_FILES['Imagem1']['name'].", não foi enviada!";
                      $errors=1;
                      }
                      if(!is_uploaded_file($HTTP_POST_FILES['Imagem2']['tmp_name'])){
                      $image_list[8].="nenhuma.jpg";
                      $errors=0;
                      }
                      if(!is_uploaded_file($HTTP_POST_FILES['Imagem3']['tmp_name'])){
                      $error.="<li>A 3ª imagem, ".$HTTP_POST_FILES['Imagem3']['name'].", não foi enviada!";
                      $errors=0;
                      }
                      if(!is_uploaded_file($HTTP_POST_FILES['Imagem4']['tmp_name'])){
                      $error.="<li>A 4ª imagem, ".$HTTP_POST_FILES['Imagem4']['name'].", não foi enviada!";
                      $errors=0;
                      }
                      if(!is_uploaded_file($HTTP_POST_FILES['Imagem5']['tmp_name'])){
                      $error.="<li>A 5ª imagem, ".$HTTP_POST_FILES['Imagem5']['name'].", não foi enviada!";
                      $errors=0;
                      }
                      if(!is_uploaded_file($HTTP_POST_FILES['Imagem6']['tmp_name'])){
                      $error.="<li>A 6ª imagem, ".$HTTP_POST_FILES['Imagem6']['name'].", não foi enviada!";
                      $errors=0;
                      }
                      if($errors==1) echo $error;
                      else{
                      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem1']['name'];
                      $image_list[8] = $image_part;
                      copy($HTTP_POST_FILES['Imagem1']['tmp_name'], "fotos/".$image_part);
                      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem2']['name'];
                      $image_list[9] = $image_part;
                      copy($HTTP_POST_FILES['Imagem2']['tmp_name'], "fotos/".$image_part);
                      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem3']['name'];
                      $image_list[10] = $image_part;
                      copy($HTTP_POST_FILES['Imagem3']['tmp_name'], "fotos/".$image_part);
                      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem4']['name'];
                      $image_list[11] = $image_part;
                      copy($HTTP_POST_FILES['Imagem4']['tmp_name'], "fotos/".$image_part);
                      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem5']['name'];
                      $image_list[12] = $image_part;
                      copy($HTTP_POST_FILES['Imagem5']['tmp_name'], "fotos/".$image_part);
                      $image_part = date("h_i_s")."_".$HTTP_POST_FILES['Imagem6']['name'];
                      $image_list[13] = $image_part;
                      copy($HTTP_POST_FILES['Imagem6']['tmp_name'], "fotos/".$image_part);
                      $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
                      $message="Nome: ".$Nome."
                      Projecto: ".$Projecto."
                      Zona: ".$Zona."
                      Modelo: ".$Modelo."
                      Alteracoes: ".$Alteracoes."
                      Outros: ".$Outros."
                      Score: ".$Score."
                      Activar: ".$Activar."
                      Imagem 1: ".$where_form_is."fotos/".$image_list[8]."
                      Imagem 2: ".$where_form_is."fotos/".$image_list[9]."
                      Imagem 3: ".$where_form_is."fotos/".$image_list[10]."
                      Imagem 4: ".$where_form_is."fotos/".$image_list[11]."
                      Imagem 5: ".$where_form_is."fotos/".$image_list[12]."
                      Imagem 6: ".$where_form_is."fotos/".$image_list[13]."
                      ";
                      
                      $img = new ImageMagick($Imagem1); 
                      $img = new ImageMagick($Imagem2); 
                      $img = new ImageMagick($Imagem3); 
                      $img = new ImageMagick($Imagem4); 
                      $img = new ImageMagick($Imagem5); 
                      $img = new ImageMagick($Imagem6); 
                      
                      $img->setTargetdir('/Zone/Galeria/Thumbnails/'); 
                      $img->Resize(100,100); 
                      $img->Save(); 
                      $img->CleanUp();
                      
                      
                      $link = mysql_connect("localhost","oc-zone","password");
                      mysql_select_db("oczone_modding",$link);
                      $query="insert into galeria (nome,projecto,zona,modelo,alteracoes,outros,score,activar,imagem1,imagem2,imagem3,imagem4,imagem5,imagem6) values ('".$Nome."','".$Projecto."','".$Zona."','".$Modelo."','".$Alteracoes."','".$Outros."','".$Score."','".$Activar."','".$image_list[8]."','".$image_list[9]."','".$image_list[10]."','".$image_list[11]."','".$image_list[12]."','".$image_list[13]."')";
                      mysql_query($query);
                      header("Refresh: 0;url=http://www.oc-zone.com");
                      }
                      ?>

                      I also did chmod 777 to that directory, because it could be because of that, but no go.

                      Also, on the target dir, you typed an "r" at the end. Should that be inserted too? (tryed with and without, had the same error).

                      On thing that bothers me, is the class file. You told me I hadn´t to change anything, but right in here:

                      var $imagemagickdir = '/usr/local/bin';

                      shoul´n´t i change to the dir of the imagick on the server (which is diferent).?

                      Thank you for all the help you´ve been giving me 😉

                        Also, on the target dir, you typed an "r" at the end. Should that be inserted too? (tryed with and without, had the same error).

                        No, was a typo of me.... leave it out, sorry.

                        On thing that bothers me, is the class file. You told me I hadn´t to change anything, but right in here:

                        var $imagemagickdir = '/usr/local/bin';

                        shoul´n´t i change to the dir of the imagick on the server (which is diferent).?

                        U r right, too... I forgot that the class wraps only wraps the calls of the binary, so u gotta change the path indeed...
                        Try it, and if it still does not work, mail again... I gonna help u with this problem till we solved everything...
                        notify me whether it works or not....
                        cu

                          also change this line (if necessary) and set the appropriate permission:

                          var $temp_dir        = '/var/tmp'; // httpd must be able to write there

                          mybe that is another problem...

                            Ok, changed the class to:

                            var $targetdir_= '';
                            var $imagemagickdir = '/usr/X11R6/bin';
                            var $temp_dir_= '/home/oc-zone/public_html/files/temp'; // httpd must be able to write there
                            var $file_history_= array();
                            var $temp_file_= '';
                            var $jpg_quality_= '65';
                            var $count_= 0;
                            var $image_data_= array();
                            var $error_= '';
                            var $verbose_= FALSE;
                            

                            tried the tempdir with

                            /var/temp
                            /var/temp/
                            files/temp
                            files/temp/
                            /files/temp
                            /files/temp/
                            /home/oc-zone/public_html/files/temp
                            /home/oc-zone/public_html/files/temp/

                            I suppose I shouldn´t use the trailing slash at the end, but tried with and without it, to make sure that wasn´t the problem. Before trying that, i made chmod 777 to the directory temp in files folder.

                            Also, I´m on a public server. Temp dir must be inside my account, right?

                            Natty_Dreadlock, thankx for spending some of your time helping me 😉

                              It's still doesn't work?? Any error message u get? or does it work now?

                              Temp dir must be inside my account, right?

                              Actually every program should be able to write to the systems tmp dir, but maybe u have to create a tmp dir in your folder when the hoster changed something.

                                No it doesn´t work. Same error: Imagemagick upload failed. Isn´t it nothing with the code I posted here? (the code of the page)?

                                  This error can only occur when u give invalid information to the constructor so that the class cannot rename it and move it to the tmp dir.
                                  So maybe just give the $FILES entries to the class and not $Imagem1 etc (e.g. $FILES["Imagem1"]) the part where.
                                  Moreover, u must create ONE class for ONE file, when u reassign $img 6 times it cannot work - u can store all the classes in one array, e.g.

                                  $images = array(new ImageMagick($_FILES["Imagem1"]), new ImageMagick($_FILES["Imagem2"]),.....);
                                  // resize & store
                                  for($i = 0; $i < sizeof($images); $i++)
                                  {
                                  $images[$i]->setTargetdir('/Zone/Galeria/Thumbnails/'); 
                                  $images[$i]->Resize(100,100); 
                                  $images[$i]->Save(); 
                                  $images[$i]->CleanUp();
                                  }
                                  

                                  This should finally solve your problem (i hope )