Autor Zpráva
unlucky
Profil
Mam skript, ktery uploadne obrazek + udela se thumbnail.
Uploadne, ale thumbnail se neudela.
Chyba: nvalid image dimensions in..+supplied argument is not a valid Image resource
radky 63-66

Funkce na vytvoreni thumbnailu pouzivam uz dlouho a fungoval. Nyni se skript nachazi v jinem adresari, ale cestu jsem uz upravil.

struktura
../../../../uploads/articles/obrazky_zde.jpg
../../../../uploads/articles/thumbs/thumbs_zde.jpg
../
<?php
include("../../../includy/dbz.php");   
include("../../../includy/main_funkce.php");
include("../../../includy/config.php");

            $error='';
$subfolder ='';      //    neco/
switch($_POST['from']){
  case "gallery":
    define('_ARTICLE_ATTACH_DIR','../../../../uploads/articles/');
  break;
  
  case "products":
    define('_ARTICLE_ATTACH_DIR','../../../../uploads/products/');
  break;
  default:
  define('_ARTICLE_ATTACH_DIR','../../../../uploads/articles/');
  break;
}
                                 
session_start();

//header('Content-Type: text/plain; charset=utf-8');


$funcNum = $_GET['CKEditorFuncNum'] ;
$data=UploadImageFile();
$url = str_replace("../../../../","../",$data['file']);
$message = $data['warning'];

echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '".$url."', '".$message."');</script>";
function makeThumbz( $pathToImages, $pathToThumbs, $thumbWidth ){

  if (!is_dir($pathToThumbs))
  {
  mkdir($pathToThumbs);
  } 
  //$aa=split("/", $pathToImages);
  //$poceta=count($aa);
  //$fname  =$aa[$poceta-1];
  $fname=basename($pathToImages);
  
  $type=strtolower(str_replace(".","",substr($pathToImages,-4)));
    if ($type=="jpeg" or $type=="jpg"){
        $img=imagecreatefromjpeg($pathToImages);
    }
    if ($type=="png"){
        $img=imagecreatefrompng($pathToImages);
    }
  if ($type=="gif"){
        $img=imagecreatefromgif($pathToImages);
    }
    
    

      $width = imagesx( $img );
      $height = imagesy( $img );

      // calculate thumbnail size
      $new_width = $thumbWidth;
      $new_height = floor( $height * ( $thumbWidth / $width ) );

      // create a new temporary image
      $tmp_img = imagecreatetruecolor( $new_width, $new_height );

      // copy and resize old image into new image
      imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

      
  $changed_name=str_replace(".","_.",$fname);
  
    $final_name=$pathToThumbs.$changed_name;
    if ($type=="jpeg" or $type=="jpg"){
        imagejpeg( $tmp_img, $final_name);
    }
    if ($type=="png"){
        imagepng( $tmp_img, $final_name);
    }
  if ($type=="gif"){
        imagegif( $tmp_img, $final_name);
    }
    
    $pix['location']= $pathToImages;
    $pix['thumb_location']=$pathToThumbs.$fname;
    return $pix;

}
function UploadImageFile()
{
        $data['file']='';
    $data['warning']='';
    if ( strncasecmp($_FILES["upload"]["type"], "image/", 6)  == 0 )
    {
        if ($_FILES["upload"]["error"] > 0)
        {
            $warning = "Return Code: " . $_FILES["upload"]["error"] ;
        }
        else
        {
            $file_name = $_FILES["upload"]["name"];
            $nname= strtolower(str_replace(" ","_",$file_name));
                   $new_name = rand(1, 100) . $nname;
          
            $move_to_file = _ARTICLE_ATTACH_DIR . $new_name;

            if (file_exists($move_to_file))
            {
                $warning = $file_name . " already exists.";
            }
            else
            {
                if( !@move_uploaded_file($_FILES["upload"]["tmp_name"], $move_to_file) )
                {
                    $warning = 'Upload Failed!';
                }else{
                  $thumbed=makeThumbz($move_to_file , _ARTICLE_ATTACH_DIR . "thumbs/" , $setup['thumb_width']);
                  echo $thumbed['thumb_location'];
                }
            }
        }
    }
    else
    {
        $warning = "Invalid file";
    }
    $data['file']=$move_to_file;
    $data['warning']=$warning;
    return $data;
}

?>
panther
Profil
unlucky:
co je v rpoměnných $new_width a $new_height, když si je vypíšeš?
unlucky
Profil
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
vsechno se vypocte na zaklade thumbwidth pri zavolani funkce. Je to tam spravne. 200

edit: aha
takze thumbwidth nic, new width nic, new height 0

aha zahada vyresena.
$setup -> funkce :)

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0