public function update_picture()
 {
     if (trim($_FILES["myfile"]["tmp_name"]) != "") {
         $images = $_FILES["myfile"]["tmp_name"];
         $new_images = "thumb_" . $this->session->userdata('std_cardid') . '_' . $_FILES["myfile"]["name"];
         copy($_FILES["myfile"]["tmp_name"], "assets/uploads/photo/" . $_FILES["myfile"]["name"]);
         $width = 150;
         //*** Fix Width & Heigh (Autu caculate) ***//
         $size = GetimageSize($images);
         $height = round($width * $size[1] / $size[0]);
         $images_orig = ImageCreateFromJPEG($images);
         $photoX = ImagesX($images_orig);
         $photoY = ImagesY($images_orig);
         $images_fin = ImageCreateTrueColor($width, $height);
         ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
         ImageJPEG($images_fin, "assets/uploads/photo/" . $new_images);
         ImageDestroy($images_orig);
         ImageDestroy($images_fin);
     }
     $fileName = $_FILES["myfile"]["name"];
     $ret[] = $fileName;
     $data_picture = array('std_picture' => $new_images);
     $this->Students_model->update_student_picture($this->session->userdata('std_cardid'), $data_picture);
     //echo  base_url()."assets/uploads/photo/".$new_images;
     redirect('/front_profiles/student_edit', 'refresh');
     //ChromePhp::log($ret);
     //exit;
 }
Exemplo n.º 2
0
function resize($image_tmp, $image_name, $width_size, $folder)
{
    $images = $image_tmp;
    $new_images = $image_name;
    $width = $width_size;
    $size = GetimageSize($images);
    $height = round($width * $size[1] / $size[0]);
    $images_orig = ImageCreateFromJPEG($images);
    $photoX = ImagesX($images_orig);
    $photoY = ImagesY($images_orig);
    $images_fin = ImageCreateTrueColor($width, $height);
    ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
    ImageJPEG($images_fin, $folder . $new_images);
    ImageDestroy($images_orig);
    ImageDestroy($images_fin);
}
Exemplo n.º 3
0
 protected function subir_imagen()
 {
     $imagen = $_FILES['logo']['name'];
     $directorio = "src/marcas_logo/";
     $fecha = date('d.m.Y_H.i.s');
     $nombre_archivo = "logo_" . $fecha;
     $i = strlen($imagen) - 1;
     $extension = '';
     while ($imagen[$i] != '.') {
         $extension = $imagen[$i] . $extension;
         $i--;
     }
     $nombre_archivo = $nombre_archivo . '.' . $extension;
     $new_images = $nombre_archivo;
     $images = $_FILES['logo']['tmp_name'];
     switch ($extension) {
         case "jpg":
         case "jpeg":
         case "JPG":
         case "JPEG":
             $thumb = ImageCreateFromJPEG($images);
             break;
         case "gif":
         case "GIF":
             $thumb = imagecreatefromgif($images);
             break;
         case "png":
         case "PNG":
             try {
                 $thumb = imagecreatefrompng($images);
             } catch (Exception $e) {
                 $this->resultado = -1;
                 exit;
             }
             break;
         default:
             $this->resultado = 2;
             exit;
             break;
     }
     copy($images, '../' . $directorio . $nombre_archivo);
     $width = 300;
     $size = GetimageSize($images);
     if ($size != 0) {
         $height = round($width * $size[1] / $size[0]);
         //$height = 150;
     }
     $newwidth = 150;
     $newheight = $height;
     $srcWidth = imagesx($thumb);
     $srcHeight = imagesy($thumb);
     $newImg = imagecreatetruecolor($width, $height);
     imagealphablending($newImg, false);
     imagesavealpha($newImg, true);
     $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
     imagefilledrectangle($newImg, 0, 0, $width, $height, $transparent);
     imagecopyresampled($newImg, $thumb, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
     imagepng($newImg, '../' . $directorio . $new_images);
     /*
                 imagealphablending($thumb, false);
                 imagesavealpha($thumb, true);  
                 imagealphablending($thumb, true);
                 /*$photoX = ImagesX($thumb);
                 $photoY = ImagesY($thumb);
                 $new_image = imagecreatetruecolor ( $width, $height );
                 imagecopyresampled($new_image, $thumb, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);*/
     /*switch($extension){
           case "jpg": case "jpeg":
               ImageJPEG($new_image,'../'.$directorio.$new_images);
               break;
           case "gif":
               imagegif($new_image,'../'.$directorio.$new_images);
               break;
           case "png":
               echo "helo";
               imagepng ($new_image,'../'.$directorio.$new_images, 9);
               break;
           default:
               $this->resultado = 2;
               exit();
       }*/
     ImageDestroy($thumb);
     if (!is_dir('../' . $directorio)) {
         mkdir('../' . $directorio, 0777);
     }
     return mysqli_real_escape_string($this->sql_con, $directorio . $nombre_archivo);
 }
Exemplo n.º 4
0
<?php

if ($_FILES['file']['error'] > 0) {
    $erreur = "Erreur lors du transfert";
} else {
    $extensions_valides = array('jpg', 'jpeg', 'gif', 'png');
    //1. strrchr renvoie l'extension avec le point (« . »).
    //2. substr(chaine,1) ignore le premier caractère de chaine.
    //3. strtolower met l'extension en minuscules.
    $extension_upload = strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1));
    if (!in_array($extension_upload, $extensions_valides)) {
        $erreur = "Unexpected file type";
        echo $erreur;
    } else {
        $width = 500;
        //*** Fix Width & Heigh (Autu caculate) ***//
        $size = GetimageSize($_FILES['file']['tmp_name']);
        $height = round($width * $size[1] / $size[0]);
        $images_orig = ImageCreateFromJPEG($_FILES['file']['tmp_name']);
        $photoX = ImagesX($images_orig);
        $photoY = ImagesY($images_orig);
        $images_fin = ImageCreateTrueColor($width, $height);
        ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
        $name = "../uploads/" . $_POST['title'] . "." . $extension_upload;
        ImageJPEG($images_fin, $name);
        header("location:../uploadImages.php");
    }
}
Exemplo n.º 5
0
 protected function subir_imagen()
 {
     $imagen = $_FILES['imagen']['name'];
     $directorio = "src/productos/";
     $fecha = date('d.m.Y_H.i.s');
     $nombre_archivo = "logo_" . $fecha;
     $i = strlen($imagen) - 1;
     $extension = '';
     while ($imagen[$i] != '.') {
         $extension = $imagen[$i] . $extension;
         $i--;
     }
     $nombre_archivo = $nombre_archivo . '.' . $extension;
     $new_images = $nombre_archivo;
     //
     $images = $_FILES["imagen"]["tmp_name"];
     copy($images, '../' . $directorio . $nombre_archivo);
     $width = 150;
     //*** Fix Width & Heigh (Autu caculate) ***//
     $size = GetimageSize($images);
     $height = round($width * $size[1] / $size[0]);
     switch ($extension) {
         case "jpg":
         case "jpeg":
         case "JPG":
         case "JPEG":
             $images_orig = ImageCreateFromJPEG($images);
             break;
         case "gif":
         case "GIF":
             $images_orig = imagecreatefromgif($images);
             break;
         case "png":
         case "PNG":
             $images_orig = imagecreatefrompng($images);
             break;
         default:
             $this->resultado = 2;
             exit;
     }
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     ImageJPEG($images_fin, '../' . $directorio . $new_images);
     ImageDestroy($images_orig);
     //ImageDestroy($images_fin);
     //
     if (!is_dir('../' . $directorio)) {
         mkdir('../' . $directorio, 0777);
     }
     /*if ($imagen && move_uploaded_file($images_fin,'../'.$directorio.$nombre_archivo))
       {
          $this->resultado = 1;
       }else{
           $this->resultado = 0;
       }*/
     return mysqli_real_escape_string($this->sql_con, $directorio . $nombre_archivo);
 }
Exemplo n.º 6
0
function jResize2($tmp, $name)
{
    copy($_FILES, "Photos/" . $_FILES["userfile"]["name"]);
    $width = 500;
    //*** Fix Width & Heigh (Autu caculate) ***//
    $size = GetimageSize($tmp);
    $height = round($width * $size[1] / $size[0]);
    $images_orig = ImageCreateFromJPEG($tmp);
    $photoX = ImagesX($images_orig);
    $photoY = ImagesY($images_orig);
    $images_fin = ImageCreateTrueColor($width, $height);
    ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
    ImageJPEG($images_fin, "Photos/" . $name);
    ImageDestroy($images_orig);
    ImageDestroy($images_fin);
}
 //count file
 $count = count($_FILES["file_"]["name"]);
 $title_rep = str_replace(" ", "", $en_title);
 for ($i = 1; $i < $count; $i++) {
     $file_name = $_FILES["file_"]["name"][$i];
     if ($file_name != "") {
         //file rename
         $f_name = explode(".", $file_name);
         $f_rename = $maxID . "_" . $i . "_" . $title_rep . "." . $f_name['1'];
         //Resize//
         $images = $_FILES["file_"]["tmp_name"][$i];
         $new_images = $f_rename;
         //copy($_FILES["file_"]["tmp_name"][$i],"file/resize1/".$_FILES["file_"]["name"][$i]); //size original
         $width = 500;
         //*** Fix Width & Heigh (Autu caculate) ***//
         $size = GetimageSize($images);
         $height = round($width * $size[1] / $size[0]);
         $images_orig = ImageCreateFromJPEG($images);
         $photoX = ImagesX($images_orig);
         $photoY = ImagesY($images_orig);
         $images_fin = ImageCreateTrueColor($width, $height);
         ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
         ImageJPEG($images_fin, "file/news/" . $new_images);
         //size thumbnails
         ImageDestroy($images_orig);
         ImageDestroy($images_fin);
         //Resize//
         //if(move_uploaded_file($_FILES["file_"]["tmp_name"][$i],"file/news/".$f_rename))
         //{
         $result_insert = mysqli_query($mysqli, "INSERT INTO w_news_file (id,news_id,name) VALUES (NULL, '{$maxID}','{$f_rename}')");
         //}
Exemplo n.º 8
0
    // 1以上の値
}
$height = 0;
// 指定しない場合は0 指定する場合は1以上の値
include_once '../../mainfile.php';
$photo_path = $_GET['photo'];
$photo_path = XOOPS_ROOT_PATH . $photo_path;
if (!isset($photo_path)) {
    return array(0, "イメージのパスが設定されていません。");
    exit;
}
if (!file_exists($photo_path)) {
    return array(0, "指定されたパスにファイルが見つかりません。");
    exit;
}
$size = @GetimageSize($photo_path);
$re_size = $size;
//アスペクト比固定処理
$tmp_width = $size[0] / $width;
if ($height != 0) {
    $tmp_height = $size[1] / $height;
}
if ($tmp_width > 1 || $tmp_height > 1) {
    if ($height == 0) {
        if ($tmp_width > 1) {
            $re_size[0] = $width;
            $re_size[1] = $size[1] * $width / $size[0];
        }
    } else {
        if ($tmp_width > $tmp_height) {
            $re_size[0] = $width;
Exemplo n.º 9
0
function _upload_Image($directory, $input_name, $max_size, $setW_H, $setThumbnail)
{
    $array = array();
    $index = 0;
    if ($_FILES) {
        $img_name = $_FILES[$input_name]['name'];
        $img_type = $_FILES[$input_name]['type'];
        $img_size = $_FILES[$input_name]['size'];
        $img_tmp = $_FILES[$input_name]['tmp_name'];
        if (is_array($img_tmp)) {
            if (file_exists($directory)) {
                for ($i = 0; $i < count($img_name); $i++) {
                    if ($img_type[$i] == "image/jpeg" || $img_type[$i] == "image/png" || $img_type[$i] == "image/gif") {
                        if ($max_size > $img_size[$i] / 1024) {
                            $img_W = getimagesize($img_tmp[$i]);
                            if ($setW_H < $img_W[0] && $setW_H < $img_W[0]) {
                                if (!file_exists($directory . $img_name[$i])) {
                                    $nameRandom = set_namefileUpload($img_name[$i], "Img-");
                                    $content = $directory . $nameRandom;
                                    if (copy($img_tmp[$i], $content)) {
                                        $images = $img_tmp[$i];
                                        if (!file_exists($directory . "thumbnail/")) {
                                            mkdir($directory . "thumbnail");
                                        }
                                        $new_images = $directory . "thumbnail/" . "thumbnails_" . $nameRandom;
                                        $width = $setThumbnail;
                                        //*** Fix Width & Heigh (Autu caculate) ** */
                                        $size = GetimageSize($images);
                                        $height = round($width * $size[1] / $size[0]);
                                        if (ereg("(gif)\$", $img_name[$i])) {
                                            $images_orig = imagecreatefromgif($images);
                                        } elseif (ereg("(png)\$", $img_name[$i])) {
                                            $images_orig = imagecreatefrompng($images);
                                        } else {
                                            $images_orig = imagecreatefromjpeg($images);
                                        }
                                        $photoX = ImagesX($images_orig);
                                        $photoY = ImagesY($images_orig);
                                        $images_fin = ImageCreateTrueColor($width, $height);
                                        ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
                                        if (ereg("(gif)\$", $img_name[$i])) {
                                            imageGIF($images_fin, $new_images);
                                        } elseif (ereg("(png)\$", $img_name[$i])) {
                                            imagePNG($images_fin, $new_images);
                                        } else {
                                            ImageJPEG($images_fin, $new_images);
                                        }
                                        ImageDestroy($images_orig);
                                        ImageDestroy($images_fin);
                                        $array['data'][$index] = $nameRandom;
                                        $array['sucess'] .= "คัดลอกไฟล์ {$img_name[$i]} สำเร็จ !<br />";
                                        $index++;
                                    } else {
                                        $array['error'] .= "คัดลอกไฟล์ {$img_name[$i]} ไม่สำเร็จ !<br />";
                                    }
                                } else {
                                    $array['error'] .= "มีชื่อไฟล์ {$img_name[$i]} แล้ว กรุณาเปลี่ยนชื่อ !<br />";
                                }
                            } else {
                                $array['error'] .= "ไฟล์ {$img_name[$i]} มีขนาดความกว้างความสูงน้อยเกินไป !<br />";
                            }
                        } else {
                            $array['error'] .= "ไฟล์ {$img_name[$i]} มีขนาดมากกว่า {$max_size} KB !<br />";
                        }
                    } else {
                        $array['error'] .= "ระบบไม่รองรับกับไฟล์ {$img_name[$i]} นี้ !<br />";
                    }
                }
            } else {
                if (mkdir($directory)) {
                    for ($i = 0; $i < count($img_name); $i++) {
                        if ($img_type[$i] == "image/jpeg" || $img_type[$i] == "image/png" || $img_type[$i] == "image/gif") {
                            if ($max_size > $img_size[$i] / 1024) {
                                $img_W = getimagesize($img_tmp[$i]);
                                if ($setW_H < $img_W[0] && $setW_H < $img_W[0]) {
                                    if (!file_exists($directory . $img_name[$i])) {
                                        $nameRandom = set_namefileUpload($img_name[$i], "Img-");
                                        $content = $directory . $nameRandom;
                                        if (copy($img_tmp[$i], $content)) {
                                            $images = $img_tmp[$i];
                                            if (!file_exists($directory . "thumbnail/")) {
                                                mkdir($directory . "thumbnail");
                                            }
                                            $new_images = $directory . "thumbnail/" . "thumbnails_" . $nameRandom;
                                            $width = $setThumbnail;
                                            //*** Fix Width & Heigh (Autu caculate) ** */
                                            $size = GetimageSize($images);
                                            $height = round($width * $size[1] / $size[0]);
                                            if (ereg("(gif)\$", $img_name[$i])) {
                                                $images_orig = imagecreatefromgif($images);
                                            } elseif (ereg("(png)\$", $img_name[$i])) {
                                                $images_orig = imagecreatefrompng($images);
                                            } else {
                                                $images_orig = imagecreatefromjpeg($images);
                                            }
                                            $photoX = ImagesX($images_orig);
                                            $photoY = ImagesY($images_orig);
                                            $images_fin = ImageCreateTrueColor($width, $height);
                                            ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
                                            if (ereg("(gif)\$", $img_name[$i])) {
                                                imageGIF($images_fin, $new_images);
                                            } elseif (ereg("(png)\$", $img_name[$i])) {
                                                imagePNG($images_fin, $new_images);
                                            } else {
                                                ImageJPEG($images_fin, $new_images);
                                            }
                                            ImageDestroy($images_orig);
                                            ImageDestroy($images_fin);
                                            $array['data'][$index] = $nameRandom;
                                            $array['sucess'] .= "คัดลอกไฟล์ {$img_name[$i]} สำเร็จ !<br />";
                                            $index++;
                                        } else {
                                            $array['error'] .= "คัดลอกไฟล์ {$img_name[$i]} ไม่สำเร็จ !<br />";
                                        }
                                    } else {
                                        $array['error'] .= "มีชื่อไฟล์ {$img_name[$i]} แล้ว กรุณาเปลี่ยนชื่อ !<br />";
                                    }
                                } else {
                                    $array['error'] .= "ไฟล์ {$img_name[$i]} มีขนาดความกว้างความสูงน้อยเกินไป !<br />";
                                }
                            } else {
                                $array['error'] .= "ไฟล์ {$img_name[$i]} มีขนาดมากกว่า {$max_size} KB !<br />";
                            }
                        } else {
                            $array['error'] .= "ระบบไม่รองรับกับไฟล์ {$img_name[$i]} นี้ !<br />";
                        }
                    }
                } else {
                    $array['error'] .= "โฟล์เดอร์ {$directory} ไม่มีกรุณาสร้าง โฟล์เดอร์ดังกล่าว !<br />";
                }
            }
        } else {
            if (file_exists($directory)) {
                if ($img_type == "image/jpeg" || $img_type == "image/png" || $img_type == "image/gif") {
                    if ($max_size > $img_size / 1024) {
                        $img_W = getimagesize($img_tmp);
                        if ($setW_H < $img_W[0] && $setW_H < $img_W[0]) {
                            if (!file_exists($directory . $img_name)) {
                                $nameRandom = set_namefileUpload($img_name, "Img-");
                                $content = $directory . $nameRandom;
                                if (copy($img_tmp, $content)) {
                                    $images = $img_tmp;
                                    if (!file_exists($directory . "thumbnail/")) {
                                        mkdir($directory . "thumbnail");
                                    }
                                    $new_images = $directory . "thumbnail/" . "thumbnails_" . $nameRandom;
                                    $width = $setThumbnail;
                                    //*** Fix Width & Heigh (Autu caculate) ** */
                                    $size = GetimageSize($images);
                                    $height = round($width * $size[1] / $size[0]);
                                    if (ereg("(gif)\$", $img_name)) {
                                        $images_orig = imagecreatefromgif($images);
                                    } elseif (ereg("(png)\$", $img_name)) {
                                        $images_orig = imagecreatefrompng($images);
                                    } else {
                                        $images_orig = imagecreatefromjpeg($images);
                                    }
                                    $photoX = ImagesX($images_orig);
                                    $photoY = ImagesY($images_orig);
                                    $images_fin = ImageCreateTrueColor($width, $height);
                                    ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
                                    if (ereg("(gif)\$", $img_name)) {
                                        imageGIF($images_fin, $new_images);
                                    } elseif (ereg("(png)\$", $img_name)) {
                                        imagePNG($images_fin, $new_images);
                                    } else {
                                        ImageJPEG($images_fin, $new_images);
                                    }
                                    ImageDestroy($images_orig);
                                    ImageDestroy($images_fin);
                                    $array['data'][$index] = $nameRandom;
                                    $array['sucess'] .= "คัดลอกไฟล์ {$img_name} สำเร็จ !<br />";
                                    $index++;
                                } else {
                                    $array['error'] .= "คัดลอกไฟล์ {$img_name} ไม่สำเร็จ !<br />";
                                }
                            } else {
                                $array['error'] .= "มีชื่อไฟล์ {$img_name} แล้ว กรุณาเปลี่ยนชื่อ !<br />";
                            }
                        } else {
                            $array['error'] .= "ไฟล์ {$img_name} มีขนาดความกว้างความสูงน้อยเกินไป !<br />";
                        }
                    } else {
                        $array['error'] .= "ไฟล์ {$img_name[$i]} มีขนาดมากกว่า {$max_size} KB !<br />";
                    }
                } else {
                    $array['error'] .= "ระบบไม่รองรับกับไฟล์ {$img_name} นี้ !<br />";
                }
            } else {
                if (mkdir($directory)) {
                    if ($img_type == "image/jpeg" || $img_type == "image/png" || $img_type == "image/gif") {
                        if ($max_size > $img_size / 1024) {
                            $img_W = getimagesize($img_tmp);
                            if ($setW_H < $img_W[0] && $setW_H < $img_W[0]) {
                                if (!file_exists($directory . $img_name)) {
                                    $nameRandom = set_namefileUpload($img_name, "Img-");
                                    $content = $directory . $nameRandom;
                                    if (copy($img_tmp, $content)) {
                                        $images = $img_tmp;
                                        if (!file_exists($directory . "thumbnail/")) {
                                            mkdir($directory . "thumbnail");
                                        }
                                        $new_images = $directory . "thumbnail/" . "thumbnails_" . $nameRandom;
                                        $width = $setThumbnail;
                                        //*** Fix Width & Heigh (Autu caculate) ** */
                                        $size = GetimageSize($images);
                                        $height = round($width * $size[1] / $size[0]);
                                        if (ereg("(gif)\$", $img_name)) {
                                            $images_orig = imagecreatefromgif($images);
                                        } elseif (ereg("(png)\$", $img_name)) {
                                            $images_orig = imagecreatefrompng($images);
                                        } else {
                                            $images_orig = imagecreatefromjpeg($images);
                                        }
                                        $photoX = ImagesX($images_orig);
                                        $photoY = ImagesY($images_orig);
                                        $images_fin = ImageCreateTrueColor($width, $height);
                                        ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
                                        if (ereg("(gif)\$", $img_name)) {
                                            imageGIF($images_fin, $new_images);
                                        } elseif (ereg("(png)\$", $img_name)) {
                                            imagePNG($images_fin, $new_images);
                                        } else {
                                            ImageJPEG($images_fin, $new_images);
                                        }
                                        ImageDestroy($images_orig);
                                        ImageDestroy($images_fin);
                                        $array['data'][$index] = $nameRandom;
                                        $array['sucess'] .= "คัดลอกไฟล์ {$img_name} สำเร็จ !<br />";
                                        $index++;
                                    } else {
                                        $array['error'] .= "คัดลอกไฟล์ {$img_name} ไม่สำเร็จ !<br />";
                                    }
                                } else {
                                    $array['error'] .= "มีชื่อไฟล์ {$img_name} แล้ว กรุณาเปลี่ยนชื่อ !<br />";
                                }
                            } else {
                                $array['error'] .= "ไฟล์ {$img_name} มีขนาดความกว้างความสูงน้อยเกินไป !<br />";
                            }
                        } else {
                            $array['error'] .= "ไฟล์ {$img_name[$i]} มีขนาดมากกว่า {$max_size} KB !<br />";
                        }
                    } else {
                        $array['error'] .= "ระบบไม่รองรับกับไฟล์ {$img_name} นี้ !<br />";
                    }
                } else {
                    $array['error'] .= "โฟล์เดอร์ {$directory} ไม่มีกรุณาสร้าง โฟล์เดอร์ดังกล่าว !<br />";
                }
            }
        }
    }
    return $array;
}
        function save_image_picture($file_pic, $num_file) {
            $rename_file_pic = '';
            $return_file = '';
            if (!empty($file_pic)) {
                $type_file_pic = explode(".", $file_pic);
                $end_file_pic = end($type_file_pic);
                if ($end_file_pic == "png" || $end_file_pic == "jpeg" || $end_file_pic == "gif" || $end_file_pic == "jpg") {
                    $rename_file_pic = rename_files('3') + 1;
//                    copy($_FILES['pic' . $num_file]['tmp_name'], 'new_files_images/' . $rename_file_pic . "." . $end_file_pic);
                    $width = 100; //*** Fix Width & Heigh (Autu caculate) ***//
                    $size = GetimageSize($_FILES['pic' . $num_file]['tmp_name']);
                    $height = round($width * $size[1] / $size[0]);
                    $images_orig = ImageCreateFromJPEG($_FILES['pic' . $num_file]['tmp_name']);
                    $photoX = ImagesX($images_orig);
                    $photoY = ImagesY($images_orig);
                    $images_fin = ImageCreateTrueColor($width, $height);
                    ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
//                    ImageJPEG($images_fin, "new_files_images/" . $rename_file_pic . "." . $end_file_pic); 
                    ImageJPEG($images_fin, "new_files_images/" . $rename_file_pic . "." . $end_file_pic);
                    ImageDestroy($images_orig);
                    ImageDestroy($images_fin);
                    update_num_max($rename_file_pic, '3');
                }
                $return_file = $rename_file_pic . "." . $end_file_pic;
            }
            return $return_file;
        }
Exemplo n.º 11
0
 function Main($path, $width, $height, $dst_file, $header = false)
 {
     if (!isset($path)) {
         return array(0, "イメージのパスが設定されていません。");
     }
     if (!file_exists($path)) {
         return array(0, "指定されたパスにファイルが見つかりません。");
     }
     // 画像の大きさをセット
     if ($width) {
         $this->imgMaxWidth = $width;
     }
     if ($height) {
         $this->imgMaxHeight = $height;
     }
     $size = @GetimageSize($path);
     $re_size = $size;
     //アスペクト比固定処理
     if ($this->imgMaxWidth != 0) {
         $tmp_w = $size[0] / $this->imgMaxWidth;
     }
     if ($this->imgMaxHeight != 0) {
         $tmp_h = $size[1] / $this->imgMaxHeight;
     }
     if ($tmp_w > 1 || $tmp_h > 1) {
         if ($this->imgMaxHeight == 0) {
             if ($tmp_w > 1) {
                 $re_size[0] = $this->imgMaxWidth;
                 $re_size[1] = $size[1] * $this->imgMaxWidth / $size[0];
             }
         } else {
             if ($tmp_w > $tmp_h) {
                 $re_size[0] = $this->imgMaxWidth;
                 $re_size[1] = $size[1] * $this->imgMaxWidth / $size[0];
             } else {
                 $re_size[1] = $this->imgMaxHeight;
                 $re_size[0] = $size[0] * $this->imgMaxHeight / $size[1];
             }
         }
     }
     $imagecreate = function_exists("imagecreatetruecolor") ? "imagecreatetruecolor" : "imagecreate";
     $imageresize = function_exists("imagecopyresampled") ? "imagecopyresampled" : "imagecopyresized";
     switch ($size[2]) {
         // gif形式
         case "1":
             if (function_exists("imagecreatefromgif")) {
                 $src_im = imagecreatefromgif($path);
                 $dst_im = $imagecreate($re_size[0], $re_size[1]);
                 $transparent = imagecolortransparent($src_im);
                 $colorstotal = imagecolorstotal($src_im);
                 $dst_im = imagecreate($re_size[0], $re_size[1]);
                 if (0 <= $transparent && $transparent < $colorstotal) {
                     imagepalettecopy($dst_im, $src_im);
                     imagefill($dst_im, 0, 0, $transparent);
                     imagecolortransparent($dst_im, $transparent);
                 }
                 $imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
                 if (function_exists("imagegif")) {
                     // 画像出力
                     if ($header) {
                         header("Content-Type: image/gif");
                         imagegif($dst_im);
                         return "";
                     } else {
                         $dst_file = $dst_file . ".gif";
                         if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) {
                             // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ)
                             copy($path, $dst_file);
                         } else {
                             imagegif($dst_im, $dst_file);
                         }
                     }
                     imagedestroy($src_im);
                     imagedestroy($dst_im);
                 } else {
                     // 画像出力
                     if ($header) {
                         header("Content-Type: image/png");
                         imagepng($dst_im);
                         return "";
                     } else {
                         $dst_file = $dst_file . ".png";
                         if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) {
                             // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ)
                             copy($path, $dst_file);
                         } else {
                             imagepng($dst_im, $dst_file);
                         }
                     }
                     imagedestroy($src_im);
                     imagedestroy($dst_im);
                 }
             } else {
                 // サムネイル作成不可の場合(旧バージョン対策)
                 $dst_im = imageCreate($re_size[0], $re_size[1]);
                 imageColorAllocate($dst_im, 255, 255, 214);
                 //背景色
                 // 枠線と文字色の設定
                 $black = imageColorAllocate($dst_im, 0, 0, 0);
                 $red = imageColorAllocate($dst_im, 255, 0, 0);
                 imagestring($dst_im, 5, 10, 10, "GIF {$size['0']}x{$size['1']}", $red);
                 imageRectangle($dst_im, 0, 0, $re_size[0] - 1, $re_size[1] - 1, $black);
                 // 画像出力
                 if ($header) {
                     header("Content-Type: image/png");
                     imagepng($dst_im);
                     return "";
                 } else {
                     $dst_file = $dst_file . ".png";
                     imagepng($dst_im, $dst_file);
                 }
                 imagedestroy($src_im);
                 imagedestroy($dst_im);
             }
             break;
             // jpg形式
         // jpg形式
         case "2":
             $src_im = imageCreateFromJpeg($path);
             $dst_im = $imagecreate($re_size[0], $re_size[1]);
             $imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
             // 画像出力
             if ($header) {
                 header("Content-Type: image/jpeg");
                 imageJpeg($dst_im);
                 return "";
             } else {
                 $dst_file = $dst_file . ".jpg";
                 if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) {
                     // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ)
                     copy($path, $dst_file);
                 } else {
                     imageJpeg($dst_im, $dst_file);
                 }
             }
             imagedestroy($src_im);
             imagedestroy($dst_im);
             break;
             // png形式
         // png形式
         case "3":
             $src_im = imageCreateFromPNG($path);
             $colortransparent = imagecolortransparent($src_im);
             $has_alpha = ord(file_get_contents($path, false, null, 25, 1)) & 0x4;
             if ($colortransparent > -1 || $has_alpha) {
                 $dst_im = $imagecreate($re_size[0], $re_size[1]);
                 // アルファチャンネルが存在する場合はそちらを使用する
                 if ($has_alpha) {
                     imagealphablending($dst_im, false);
                     imagesavealpha($dst_im, true);
                 }
                 imagepalettecopy($dst_im, $src_im);
                 imagefill($dst_im, 0, 0, $colortransparent);
                 imagecolortransparent($dst_im, $colortransparent);
                 imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
             } else {
                 $dst_im = $imagecreate($re_size[0], $re_size[1]);
                 imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
                 imagecolorstotal($src_im) == 0 ? $colortotal = 65536 : ($colortotal = imagecolorstotal($src_im));
                 imagetruecolortopalette($dst_im, true, $colortotal);
             }
             // 画像出力
             if ($header) {
                 header("Content-Type: image/png");
                 imagepng($dst_im);
                 return "";
             } else {
                 $dst_file = $dst_file . ".png";
                 if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) {
                     // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ)
                     copy($path, $dst_file);
                 } else {
                     imagepng($dst_im, $dst_file);
                 }
             }
             imagedestroy($src_im);
             imagedestroy($dst_im);
             break;
         default:
             return array(0, "イメージの形式が不明です。");
     }
     return array(1, $dst_file);
 }
Exemplo n.º 12
0
 public function houseImgUpload($hid, $file)
 {
     $filename = $file['name'];
     $type = $file['type'];
     $source = $file['tmp_name'];
     $typename = explode("/", $type);
     $accepted_types = array('jpeg', 'png', 'gif', 'jpg');
     $temp_path = 'img_temp';
     if (is_dir($temp_path)) {
         chmod($temp_path, 0777);
     } else {
         mkdir($temp_path, 0777);
     }
     foreach ($accepted_types as $mime_type) {
         if ($mime_type == $typename[1]) {
             $status = 'OK';
             break;
         }
     }
     if ($status == 'OK') {
         //start resize
         $width = 600;
         $size = GetimageSize($source);
         $height = round($width * $size[1] / $size[0]);
         switch ($typename[1]) {
             case 'jpg':
                 $image = imagecreatefromjpeg($source);
                 break;
             case 'jpeg':
                 $image = imagecreatefromjpeg($source);
                 break;
             case 'png':
                 $image = imagecreatefrompng($source);
                 break;
             case 'gif':
                 $image = imagecreatefromgif($source);
                 break;
             default:
                 $image = imagecreatefromjpeg($source);
         }
         $x = imagesx($image);
         $y = imagesy($image);
         $imgfin = ImageCreateTrueColor($width, $height);
         ImageCopyResampled($imgfin, $image, 0, 0, 0, 0, $width + 1, $height + 1, $x, $y);
         ImageJPEG($imgfin, "img_temp/" . $hid . '_' . $filename);
         //end resize
         //start read image
         $img_temp = "img_temp/" . $hid . '_' . $filename;
         //
         $of = fopen($img_temp, 'r');
         $rb = fread($of, filesize($img_temp));
         fclose($of);
         $img = addslashes($rb);
         //end read image
         $sql = "update house set housepic='{$img}',dateupdate=DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%s') where hcode='{$hid}'";
         $upload = $this->conn->prepare($sql);
         $upload->execute();
         unlink($img_temp);
         return 'OK';
     } else {
         return 'NOT';
     }
 }
Exemplo n.º 13
0
 protected function subir_imagen()
 {
     $imagen = $_FILES['imagen']['name'];
     $directorio = "../src/avatar_usuarios/";
     $fecha = date('d.m.Y_H.i.s');
     $nombre_archivo = "avatar" . $fecha;
     $i = strlen($imagen) - 1;
     $extension = '';
     while ($imagen[$i] != '.') {
         $extension = $imagen[$i] . $extension;
         $i--;
     }
     $nombre_archivo = $nombre_archivo . '.' . $extension;
     $new_images = $nombre_archivo;
     //
     $images = $_FILES["imagen"]["tmp_name"];
     switch ($extension) {
         case "jpg":
         case "jpeg":
             $images_orig = ImageCreateFromJPEG($images);
             break;
         case "gif":
             $images_orig = imagecreatefromgif($images);
             break;
         case "png":
             $images_orig = imagecreatefrompng($images);
             break;
         default:
             $this->datos["respuesta"] = 7;
             exit;
             break;
     }
     copy($images, $directorio . $nombre_archivo);
     $width = 300;
     //*** Fix Width & Heigh (Autu caculate) ***//
     $size = GetimageSize($images);
     $height = round($width * $size[1] / $size[0]);
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     ImageJPEG($images_fin, $directorio . $new_images);
     ImageDestroy($images_orig);
     //ImageDestroy($images_fin);
     //
     if (!is_dir($directorio)) {
         mkdir($directorio, 0777);
     }
     return mysqli_real_escape_string($this->sql_con, $directorio . $nombre_archivo);
 }
Exemplo n.º 14
0
        $imgtype = $rowData2['ProfileType'];
        $imgfile = "Profile/{$rowData2['ProfilePic']}";
        $imgname = $rowData2['ProfilePic'];
        if ($imgtype == NULL) {
            $imgtype = 'image/jpeg';
            $imgfile = "Profile2/thumbnails_profilePic.jpg";
            $imgname = "profilePic.jpg";
            $imgbinary = fread(fopen($imgfile, "r"), filesize($imgfile));
            echo "<img src='data:image/{$imgtype};base64," . base64_encode($imgbinary) . "' '/>";
        } else {
            //http://stackoverflow.com/questions/9650572/resize-image-php
            $new_images = "thumbnails_" . $imgname;
            //copy($rowData2,"Photos/".$rowData2['MediaTitle']);
            $height = 105;
            //*** Fix Width & Heigh (Autu caculate) ***//
            $size = GetimageSize($imgfile);
            $width = round($height * $size[0] / $size[1]);
            $images_orig = ImageCreateFromJPEG($imgfile);
            $photoX = ImagesX($images_orig);
            $photoY = ImagesY($images_orig);
            $images_fin = ImageCreateTrueColor($width, $height);
            ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
            ImageJPEG($images_fin, "Profile2/" . $new_images);
            $imgfile = "Profile2/" . $new_images;
            $imgbinary = fread(fopen($imgfile, "r"), filesize($imgfile));
            echo "<img src='data:image/{$imgtype};base64," . base64_encode($imgbinary) . "' '/>";
        }
        ImageDestroy($images_orig);
        ImageDestroy($images_fin);
    }
}
 public static function compressedFotoBeritaUmum($img)
 {
     $imageFileType = explode('.', $img);
     $imageFileType = $imageFileType[1];
     $targetFile = '../../../View/img/Upload/beritaUmum/' . $img;
     $tempImg = '../../../View/img/Upload/beritaUmum/_' . $img;
     $finalImg = 'http://localhost/SIMasjid/View/img/Upload/beritaUmum/_' . $img;
     if (file_exists($tempImg)) {
         unlink($tempImg);
     }
     if (!file_exists($tempImg)) {
         if (copy($targetFile, $tempImg)) {
             $size = GetimageSize($tempImg);
             $width = 1000;
             $height = round($width * $size[1] / $size[0]);
             if ($imageFileType == 'JPEG' || $imageFileType == 'jpeg' || $imageFileType == 'JPG' || $imageFileType == 'jpg') {
                 $images_orig = ImageCreateFromJPEG($tempImg);
             } else {
                 if ($imageFileType == 'PNG' || $imageFileType == 'png') {
                     $images_orig = imagecreatefrompng($tempImg);
                 } else {
                     if ($imageFileType == 'GIF' || $imageFileType == 'gif') {
                         $images_orig = imagecreatefromgif($tempImg);
                     } else {
                         if ($imageFileType == 'BMP' || $imageFileType == 'bmp') {
                             $images_orig = imagecreatefromwbmp($tempImg);
                         }
                     }
                 }
             }
             $photoX = ImagesX($images_orig);
             $photoY = ImagesY($images_orig);
             $images_fin = ImageCreateTrueColor($width, $height);
             if ($imageFileType == 'PNG' || $imageFileType == 'png') {
                 imagealphablending($images_fin, false);
                 imagesavealpha($images_fin, true);
                 $transparent = imagecolorallocatealpha($images_fin, 255, 255, 255, 127);
                 imagefilledrectangle($images_fin, 0, 0, $w, $h, $transparent);
             }
             ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
             if ($imageFileType == 'JPEG' || $imageFileType == 'jpeg' || $imageFileType == 'JPG' || $imageFileType == 'jpg') {
                 ImageJPEG($images_fin, $tempImg);
             } else {
                 if ($imageFileType == 'PNG' || $imageFileType == 'png') {
                     imagepng($images_fin, $tempImg);
                 } else {
                     if ($imageFileType == 'GIF' || $imageFileType == 'gif') {
                         imagegif($images_fin, $tempImg);
                     } else {
                         if ($imageFileType == 'BMP' || $imageFileType == 'bmp') {
                             imagewbmp($images_fin, $tempImg);
                         }
                     }
                 }
             }
             ImageDestroy($images_orig);
             ImageDestroy($images_fin);
         } else {
             $finalImg = null;
         }
         unlink($targetFile);
     }
     return $finalImg;
 }
Exemplo n.º 16
0
 protected function subir_imagen()
 {
     if ($this->registro_nuevo) {
         return true;
     }
     $imagen = $_FILES['avatar']['name'];
     $directorio = "src/avatar_usuarios/";
     $fecha = date('d.m.Y_H.i.s');
     $nombre_archivo = "avatar_" . $fecha;
     $i = strlen($imagen) - 1;
     $extension = '';
     while ($imagen[$i] != '.') {
         $extension = $imagen[$i] . $extension;
         $i--;
     }
     $extension = strtolower($extension);
     $nombre_archivo = $nombre_archivo . '.' . $extension;
     $new_images = $nombre_archivo;
     $images = $_FILES['avatar']['tmp_name'];
     switch ($extension) {
         case "jpg":
         case "jpeg":
             $thumb = ImageCreateFromJPEG($images);
             break;
         case "gif":
             $thumb = imagecreatefromgif($images);
             break;
         case "png":
             try {
                 $thumb = imagecreatefrompng($images);
             } catch (Exception $e) {
                 $this->resultado = -1;
                 exit;
             }
             break;
         default:
             $this->resultado = 2;
             exit;
             break;
     }
     copy($images, '../' . $directorio . $nombre_archivo);
     $width = 300;
     $size = GetimageSize($images);
     if ($size != 0) {
         $height = round($width * $size[1] / $size[0]);
         //$height = 150;
     }
     $newwidth = 150;
     $newheight = $height;
     $srcWidth = imagesx($thumb);
     $srcHeight = imagesy($thumb);
     $newImg = imagecreatetruecolor($width, $height);
     imagealphablending($newImg, false);
     imagesavealpha($newImg, true);
     $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
     imagefilledrectangle($newImg, 0, 0, $width, $height, $transparent);
     imagecopyresampled($newImg, $thumb, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
     imagepng($newImg, '../' . $directorio . $new_images);
     ImageDestroy($thumb);
     if (!is_dir('../' . $directorio)) {
         mkdir('../' . $directorio, 0777);
     }
     return mysqli_real_escape_string($this->sql_con, $directorio . $nombre_archivo);
 }
Exemplo n.º 17
0
 public function uploadAction()
 {
     App_Log::get()->debug($this, 'uploadAction');
     $request = $this->getRequest();
     $fileDescription = $request->getParam('file_description', '');
     $this->_folder = $request->getParam('file_folder', 'all');
     //if ($request->getPost ()) {
     App_Log::get()->debug($this, 'request->getPost');
     try {
         if (!empty($_FILES)) {
             $this->_helper->layout()->disableLayout();
             $tempFile = $_FILES['Filedata']['tmp_name'];
             $fileName = $_FILES['Filedata']['name'];
             $fileName = iconv("UTF-8", "TIS-620", $fileName);
             $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
             $targetFile = str_replace('//', '/', $targetPath) . $fileName;
             App_Log::get()->debug($this, "{$fileName} \n ");
             $fileTypes = explode(".", $fileName);
             $index = count($fileTypes) - 1;
             $fileTypes = $fileTypes[$index];
             App_Log::get()->debug($this, "{$fileTypes} \n ");
             $images = $tempFile;
             $new_images = "Thumbnails_" . $fileName;
             $thumbnailPath = "/files/" . $new_images;
             $path = "/files/" . $fileName;
             //copy ( $_FILES ["fileUpload"] ["tmp_name"], APPLICATION_PATH . "/data" . $fileName );
             $width = 100;
             //*** Fix Width & Heigh (Autu caculate) ***//
             $size = GetimageSize($images);
             $height = round($width * $size[1] / $size[0]);
             switch (strtolower($fileTypes)) {
                 case 'jpg':
                 case 'jpeg':
                     $images_orig = @ImageCreateFromJPEG($images);
                     break;
                 case 'png':
                     $images_orig = @ImageCreateFromPNG($images);
                     break;
                 case 'gif':
                     $images_orig = @ImageCreateFromGIF($images);
                     break;
             }
             if (in_array($fileTypes, array('jpg', 'jpeg', 'png', 'gif'))) {
                 $photoX = ImagesX($images_orig);
                 $photoY = ImagesY($images_orig);
                 $images_fin = ImageCreateTrueColor($width, $height);
                 ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
                 ImageJPEG($images_fin, $targetPath . $new_images);
                 ImageDestroy($images_orig);
                 ImageDestroy($images_fin);
             }
             move_uploaded_file($tempFile, $targetFile);
             $file = new Cms_Model_File();
             App_Log::get()->debug($this, 'create new file');
             $fileNameUTF = iconv("TIS-620", "UTF-8", $fileName);
             $file->setName($fileNameUTF)->setPath($path)->setThumbnailPath($thumbnailPath)->setType($fileTypes)->setDescription($fileDescription);
             if ($this->_folder != 'all') {
                 $file->setFolder($this->_folder);
             }
             $file->save();
             echo "1";
         }
     } catch (Exception $e) {
         App_Log::get()->debug($this, $e->getMessage());
         echo "0";
     }
     //}
 }
function resizeImageCrop($image, $image_new_name, $image_width, $image_height, $transparent = false)
{
    global $CFG;
    if (!file_exists($image)) {
        return false;
    }
    $size = GetimageSize($image);
    $orig_w = $size[0];
    $orig_h = $size[1];
    $ratio_src = $orig_w / $orig_h;
    $ratio_target = $image_width / $image_height;
    $image_new = ImageCreateTrueColor($image_width, $image_height);
    if (!$transparent) {
        $bg_colour = imagecolorallocate($image_new, $CFG->block_oppia_mobile_export_thumb_bg_r, $CFG->block_oppia_mobile_export_thumb_bg_g, $CFG->block_oppia_mobile_export_thumb_bg_b);
        imagefill($image_new, 0, 0, $bg_colour);
    } else {
        imagealphablending($image_new, false);
        imagesavealpha($image_new, true);
    }
    switch ($size['mime']) {
        case 'image/jpeg':
            $image_src = imagecreatefromjpeg($image);
            break;
        case 'image/png':
            $image_src = imagecreatefrompng($image);
            break;
        case 'image/gif':
            $image_src = imagecreatefromgif($image);
            break;
    }
    if ($ratio_src > $ratio_target) {
        $crop = floor(($orig_w - $orig_h * $image_width / $image_height) / 2);
        imagecopyresampled($image_new, $image_src, 0, 0, $crop, 0, $image_width, $image_height, $orig_w - 2 * $crop, $orig_h);
    } else {
        $crop = floor(($orig_h - $orig_w * $image_height / $image_width) / 2);
        imagecopyresampled($image_new, $image_src, 0, 0, 0, $crop, $image_width, $image_height, $orig_w, $orig_h - 2 * $crop);
    }
    $image_new_name = $image_new_name . ".png";
    imagepng($image_new, $image_new_name, 9);
    imagedestroy($image_new);
    imagedestroy($image_src);
    return $image_new_name;
}
Exemplo n.º 19
0
         $image_id = $item + 1;
         // add 1 to max
     }
 }
 // Free the statement identifier when closing the connection
 oci_free_statement($stid);
 // now add the new data to the images table
 $date = $_POST['createdate'];
 $lob = oci_new_descriptor($conn, OCI_D_LOB);
 $thumblob = oci_new_descriptor($conn, OCI_D_LOB);
 $stmt = oci_parse($conn, "INSERT INTO images(image_id, sensor_id, date_created, description, thumbnail, recoreded_data) VALUES ('{$image_id}', '{$sensor_id}', to_date('{$date}', 'dd/mm/YYYY hh24:mi:ss'), '{$description}', empty_blob(), empty_blob()) returning thumbnail, recoreded_data into :thumbnail, :recoreded_data");
 oci_bind_by_name($stmt, ':thumbnail', $thumblob, -1, OCI_B_BLOB);
 oci_bind_by_name($stmt, ':recoreded_data', $lob, -1, OCI_B_BLOB);
 oci_execute($stmt, OCI_NO_AUTO_COMMIT);
 // resize image
 $size = GetimageSize($tmpName);
 $Img = ImageCreateFromJpeg($tmpName);
 $oldWidth = imagesx($Img);
 $oldHeight = imagesy($Img);
 $newWidth = 50;
 $newHeight = 50;
 $images_fin = ImageCreateTrueColor($newWidth, $newHeight);
 ImageCopyResampled($images_fin, $Img, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight);
 ob_start();
 imagejpeg($images_fin);
 $data = ob_get_contents();
 ob_end_clean();
 //echo base64_encode($data);
 $image = "<img src='data:image/jpeg;base64," . base64_encode($data) . "'>";
 //echo $image;
 $sBinaryThumbnail = base64_encode($data);
Exemplo n.º 20
-1
 public static function ResizeImage($Img, $w)
 {
     $filename = $_SERVER["DOCUMENT_ROOT"] . JURI::root(true) . "/" . $Img;
     $images = $filename;
     $new_images = $_SERVER["DOCUMENT_ROOT"] . JURI::root(true) . "/thumb/" . $Img;
     //copy("/images/thumb/"$_FILES,"Photos/".$_FILES["userfile"]["name"]);
     $width = $w;
     //*** Fix Width & Heigh (Autu caculate) ***//
     $size = GetimageSize($images);
     $height = round($width * $size[1] / $size[0]);
     if ($size[0] == "250") {
         return "The logo has the right width. Doesn't make sense resize it! Good job!";
     }
     $images_orig = ImageCreateFromJPEG($images);
     $photoX = ImagesX($images_orig);
     $photoY = ImagesY($images_orig);
     $images_fin = ImageCreateTrueColor($width, $height);
     $result = ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
     ImageJPEG($images_fin, $filename);
     ImageDestroy($images_orig);
     ImageDestroy($images_fin);
     if ($result) {
         return "Logo resized to " . $width . "px by " . $height . "px";
     } else {
         return "mmm It looks like something unexpected just happened, ask Jose!";
     }
 }