public function resize($width, $height) { $type = exif_imagetype($this->image); if ($type == 2) { $images_orig = ImageCreateFromJPEG($this->image); } elseif ($type == 3) { $images_orig = ImageCreateFromPNG($this->image); } elseif ($type == 1) { $images_orig = ImageCreateFromGIF($this->image); } else { return false; } $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 ($type == 2) { ImageJPEG($images_fin, $this->image); } elseif ($type == 3) { ImagePNG($images_fin, $this->image); } elseif ($type == 1) { ImageGIF($images_fin, $this->image); } ImageDestroy($images_orig); ImageDestroy($images_fin); return true; }
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; }
function makeThumb($path, $size, $mime = FALSE) { // Verifica se é uma imagem // @since rev 1 if ($mime === FALSE) { $mime = mime_content_type($path); } if (strpos($mime, "jpeg") !== FALSE) { $buffer = imagecreatefromjpeg($path); } elseif (strpos($mime, "bmp") !== FALSE) { $buffer = imagecreatefrombmp($path); } elseif (strpos($mime, "gif") !== FALSE) { $buffer = imagecreatefromgif($path); } elseif (strpos($mime, "png") !== FALSE) { $buffer = imagecreatefrompng($path); } else { return FALSE; } if ($buffer === FALSE) { return FALSE; } // Busca o tamanho da imagem // @since rev 1 $x = $origem_x = ImagesX($buffer); $y = $origem_y = ImagesY($buffer); // Verifica qual deve ser a proporção // @since rev 1 if ($x >= $y) { if ($x > $size) { $x1 = (int) ($x * ($size / $x)); $y1 = (int) ($y * ($size / $x)); } else { $x1 = $x; $y1 = $y; } } else { if ($y > $size) { $x1 = (int) ($x * ($size / $y)); $y1 = (int) ($y * ($size / $y)); } else { $x1 = $x; $y1 = $y; } } // Muda o tamanho da imagem // @since rev 1 $image = ImageCreateTrueColor($x1, $y1); if ($image === FALSE) { return FALSE; } ImageCopyResampled($image, $buffer, 0, 0, 0, 0, $x1 + 1, $y1 + 1, $origem_x, $origem_y); // Libera recursos // @since rev 1 ImageDestroy($buffer); // Retorna o resource // @since rev 1 return $image; }
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); }
function thumb_creator($source, $filename, $uploaddir) { $extension = "." . getExtension($filename); $new_images = "thumb_" . date(YmdHis) . $extension; $tmp_img = $source['tmp_name']; $src_size = getimagesize($tmp_img); $width = 150; $height = round($width * $src_size[1] / $src_size[0]); if ($src_size['mime'] === 'image/jpeg') { $src = imagecreatefromjpeg($tmp_img); } else { if ($src_size['mime'] === 'image/jpg') { $src = imagecreatefromjpeg($tmp_img); } else { if ($src_size['mime'] === 'image/png') { $src = imagecreatefrompng($tmp_img); } else { if ($src_size['mime'] === 'image/gif') { $src = imagecreatefromgif($tmp_img); } } } } $photoX = ImagesX($src); $photoY = ImagesY($src); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $src, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY); if ($src_size['mime'] === 'image/jpeg') { ImageJPEG($images_fin, $uploaddir . "/" . $new_images); } else { if ($src_size['mime'] === 'image/jpg') { ImageJPEG($images_fin, $uploaddir . "/" . $new_images); } else { if ($src_size['mime'] === 'image/png') { ImagePNG($images_fin, $uploaddir . "/" . $new_images); } else { if ($src_size['mime'] === 'image/gif') { ImageGIF($images_fin, $uploaddir . "/" . $new_images); } } } } }
/** * Thumbnail kép készítése */ function setThumbnail() { global $sugar_config; if (!empty($this->destination)) { $size = getimagesize($this->destination); $height = 200; $ratio = $size[0] / $size[1]; $width = round($height * $ratio); $images_orig = $this->imagecreatefromfile($this->destination); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_thumb = ImageCreateTrueColor($width, $height); if (!ImageCopyResampled($images_thumb, $images_orig, 0, 0, 0, 0, $width, $height, $photoX, $photoY)) { die("ERROR: can't resize the image"); } else { ImageJPEG($images_thumb, $sugar_config['cache_dir'] . "images/thumb/" . $this->fileName); } } }
function testThisDoesNotWorkAsExpected() { $scale = 0.75; $input_jpeg = new PelJpeg($this->file); $original = ImageCreateFromString($input_jpeg->getBytes()); $original_w = ImagesX($original); $original_h = ImagesY($original); $scaled_w = $original_w * $scale; $scaled_h = $original_h * $scale; $scaled = ImageCreateTrueColor($scaled_w, $scaled_h); ImageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h); $output_jpeg = new PelJpeg($scaled); $exif = $input_jpeg->getExif(); if ($exif !== null) { $output_jpeg->setExif($exif); } file_put_contents($this->file, $output_jpeg->getBytes()); $jpeg = new PelJpeg($this->file); $exifin = $jpeg->getExif(); $this->assertEquals($exif, $exifin); }
public function uploadImage($file, $path, $resize = [400, 200, 100]) { $filename = "photo_" . date('YmdHis') . "_" . rand() . $file->getClientOriginalName(); $file_path = public_path() . $path; $file->move($file_path, $filename); $size = getimagesize($file_path . $filename); switch (strtolower($size['mime'])) { case 'image/png': $source_image = imagecreatefrompng($file_path . $filename); break; case 'image/jpeg': $source_image = imagecreatefromjpeg($file_path . $filename); break; case 'image/gif': $source_image = imagecreatefromgif($file_path . $filename); break; default: die('image type not supported'); } $resize_url = []; foreach ($resize as $key => $value) { $width = $value; $height = round($width * $size[1] / $size[0]); $photoX = ImagesX($source_image); $photoY = ImagesY($source_image); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $source_image, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY); if (!file_exists($file_path . 'x' . $value)) { mkdir($file_path . 'x' . $value); } $resize_url[] = $path . 'x' . $value . '/' . $filename; ImageJPEG($images_fin, $file_path . 'x' . $value . '/' . $filename, 100); } ImageDestroy($source_image); ImageDestroy($images_fin); return ['__type' => 'File', 'name' => $filename, 'url' => $path . $filename, 'resize_url' => $resize_url]; }
function Img($Image, $Dw = 200, $Dh = 300, $Type = 2) { if (!File_Exists($Image)) { return False; } #如果需要生成缩略图,则将原图拷贝一下重新给$Image赋值 // IF($Type!=1){ Copy($Image, Str_Replace(".", "_x.", $Image)); $Image = Str_Replace(".", "_x.", $Image); // } var_dump($Image); #取得文件的类型,根据不同的类型建立不同的对象 $ImgInfo = GetImageSize($Image); var_dump($ImgInfo); switch ($ImgInfo[2]) { case 1: $Img = @ImageCreateFromGIF($Image); break; case 2: $Img = @ImageCreateFromJPEG($Image); break; case 3: $Img = @ImageCreateFromPNG($Image); break; } #如果对象没有创建成功,则说明非图片文件 if (empty($Img)) { #如果是生成缩略图的时候出错,则需要删掉已经复制的文件 if ($Type != 1) { Unlink($Image); } return False; } #如果是执行调整尺寸操作则 if ($Type == 1) { $w = ImagesX($Img); $h = ImagesY($Img); $width = $w; $height = $h; if ($width > $Dw) { $Par = $Dw / $width; $width = $Dw; $height = $height * $Par; if ($height > $Dh) { $Par = $Dh / $height; $height = $Dh; $width = $width * $Par; } } elseif ($height > $Dh) { $Par = $Dh / $height; $height = $Dh; $width = $width * $Par; if ($width > $Dw) { $Par = $Dw / $width; $width = $Dw; $height = $height * $Par; } } else { $width = $width; $height = $height; } $nImg = ImageCreateTrueColor($width, $height); #新建一个真彩色画布 ImageCopyReSampled($nImg, $Img, 0, 0, 0, 0, $width, $height, $w, $h); #重采样拷贝部分图像并调整大小 ImageJpeg($nImg, $Image); #以JPEG格式将图像输出到浏览器或文件 return True; #如果是执行生成缩略图操作则 } else { $w = ImagesX($Img); $h = ImagesY($Img); $width = $w; $height = $h; $nImg = ImageCreateTrueColor($Dw, $Dh); if ($h / $w > $Dh / $Dw) { #高比较大 $width = $Dw; $height = $h * $Dw / $w; $IntNH = $height - $Dh; ImageCopyReSampled($nImg, $Img, 0, -$IntNH / 1.8, 0, 0, $Dw, $height, $w, $h); } else { #宽比较大 $height = $Dh; $width = $w * $Dh / $h; $IntNW = $width - $Dw; ImageCopyReSampled($nImg, $Img, -$IntNW / 1.8, 0, 0, 0, $width, $Dh, $w, $h); } ImageJpeg($nImg, $Image); return True; } }
function uploadimg($filename, $width, $get_height, $path) { if (trim($_FILES["image"]["tmp_name"]) != "") { $tmp_images = $_FILES["image"]["tmp_name"]; // type select if ($_FILES['image']['type'] == 'image/jpeg' or $_FILES['image']['type'] == 'image/jpg' or $_FILES['image']['type'] == 'image/pjpeg') { $images = $filename . ".jpg"; //upload source image $size = getimagesize($tmp_images); //check radio widht and height $height = round($width * $size[1] / $size[0]); if ($height > $get_height) { $width = round($get_height * $size[0] / $size[1]); $height = $get_height; } $images_orig = ImageCreateFromJPEG($tmp_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, $path . $images); ImageDestroy($images_orig); ImageDestroy($images_fin); return $filename . ".jpg"; } elseif ($_FILES['image']['type'] == 'image/x-png' or $_FILES['image']['type'] == 'image/png') { $images = $filename . ".png"; $size = getimagesize($tmp_images); //check radio widht and height $height = round($width * $size[1] / $size[0]); if ($height > $get_height) { $width = round($get_height * $size[0] / $size[1]); $height = $get_height; } $images_orig = ImageCreateFromPNG($tmp_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); Imagepng($images_fin, $path . $images); ImageDestroy($images_orig); ImageDestroy($images_fin); return $filename . ".png"; } elseif ($_FILES['image']['type'] == 'image/gif') { $images = $filename . ".gif"; $size = getimagesize($tmp_images); //check radio widht and height $height = round($width * $size[1] / $size[0]); if ($height > $get_height) { $width = round($get_height * $size[0] / $size[1]); $height = $get_height; } $images_orig = ImageCreateFromgif($tmp_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); Imagegif($images_fin, $path . $images); ImageDestroy($images_orig); ImageDestroy($images_fin); return $filename . ".gif"; } else { return FALSE; } } }
function thumbMaker($imagem, $aprox, $id, $mini, $diretorio) { if (!file_exists($imagem)) { echo "<center><h3>Imagem não encontrada.</h3></center>"; return false; } // verifica se está executando sob windows ou unix-like, para a // aplicação do separador de diretórios correto. if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) { $barra = "\\"; } else { $barra = "/"; } // obtém a extensão pelo mime-type $ext = $this->getExt($imagem); if (!$ext) { echo "<center><h3>Tipo inválido</h3></center>"; return false; } // separa o nome do arquivo do(s) diretório(s) $dir_arq = explode($barra, $imagem); // monta o nome do arquivo a ser gerado (thumbnail). O sizeof abaixo obtém o número de itens // no array, dessa forma podemos pegar somente o nome do arquivo, não importando em que // diretório está. $i = sizeof($dir_arq) - 1; // pega o nome do arquivo, sem os diretórios $arquivo_miniatura = ".." . $barra . ".." . $barra . "images" . $barra . $diretorio . $barra . $mini; // imagem de origem if ($ext == "png") { $img_origem = imagecreatefrompng($imagem); } elseif ($ext == "jpg") { $img_origem = imagecreatefromjpeg($imagem); } elseif ($ext == "gif") { $img_origem = imagecreatefromgif($imagem); } // obtém as dimensões da imagem original $origem_x = ImagesX($img_origem); $origem_y = ImagesY($img_origem); $x = $origem_x; $y = $origem_y; // Aqui é feito um cálculo para aproximar o tamanho da imagem ao valor passado em $aprox. // Não importa se a foto for grande ou pequena, o thumb de todas elas será mais ou menos do // mesmo tamanho. if ($x >= $y) { if ($x > $aprox) { $x1 = (int) ($x * ($aprox / $x)); $y1 = (int) ($y * ($aprox / $x)); } else { $x1 = $x; $y1 = $y; } } else { if ($y > $aprox) { $x1 = (int) ($x * ($aprox / $y)); $y1 = (int) ($y * ($aprox / $y)); } else { $x1 = $x; $y1 = $y; } } $x = $x1; $y = $y1; // cria a imagem do thumbnail $img_final = ImageCreateTrueColor($x, $y); ImageCopyResampled($img_final, $img_origem, 0, 0, 0, 0, $x + 1, $y + 1, $origem_x, $origem_y); // o arquivo é gravado if ($ext == "png") { imagepng($img_final, $arquivo_miniatura); } elseif ($ext == "jpg") { imagejpeg($img_final, $arquivo_miniatura); } elseif ($ext == "gif") { imagegif($img_final, $arquivo_miniatura); } // a memória usada para tudo isso é liberada. ImageDestroy($img_origem); ImageDestroy($img_final); return true; }
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); }
function conv_img($src, $dest, $quality, $imgcut) { if (file_exists($src) && isset($dest)) { // path info $destInfo = pathInfo($dest); // image src size $srcSize = getImageSize($src); $maxWidth=$srcSize[0]; $maxHeight=$srcSize[1]; // image dest size $destSize[0] = width, $destSize[1] = height $srcRatio= $srcSize[0]/$srcSize[1]; //$destRatio = $maxWidth/$maxHeight; $RatioX = $maxWidth/$srcSize[0]; // 최대 이미지 너비 / 원본 이미지 너비 $RatioY = $maxHeight/$srcSize[1]; // 최대 이미지 높이 / 원본 이미지 높이 if ($imgcut == N){ //원본 이미지를 자르지 않고 비율대로 축소 할 경우 //if ($destRatio > $srcRatio){ if ($RatioX <= $RatioY) { $destSize[0] = $maxWidth; $destSize[1] = $maxWidth/$srcRatio; } else { $destSize[1] = $maxHeight; $destSize[0] = $maxHeight*$srcRatio; } } else { //원본이미지를 비율대로 축소하고 사이즈에 맞게 자를 경우 //if ($destRatio < $srcRatio){ if ($RatioX <= $RatioY) { $destSize[0] = round(($srcSize[0]*$maxHeight)/$srcSize[1]); //$maxHeight*$srcRatio; $destSize[1] = $maxHeight; $offsetX = round(($destSize[0] - $maxWidth) / 2); // 각각 좌우로 잘라낼 길이 $offsetY = 0; } else { $destSize[0] = $maxWidth; $destSize[1] = round(($srcSize[1]*$maxWidth)/$srcSize[0]); //$maxWidth/$srcRatio; $offsetX = 0; $offsetY = round(($destSize[1] - $maxHeight ) / 2); // 각각 상하로 잘라낼 길이 } } // path rectification if ($destInfo['extension'] == "gif"){ $dest = substr_replace($dest, 'jpg', -3); } // src image switch ($srcSize[2]) { case 1: //GIF $srcImage = imageCreateFromGif($src); break; case 2: //JPEG $srcImage = imageCreateFromJpeg($src); break; case 3: //PNG $srcImage = imageCreateFromPng($src); break; default: return false; break; } // true color image, with anti-aliasing if ($imgcut == N){ $destImage = imageCreateTrueColor($destSize[0], $destSize[1]); } else { $destImage = imageCreateTrueColor($maxWidth, $maxHeight); } imageAntiAlias($destImage,true); // resampling if ($imgcut == N){ imageCopyResampled($destImage, $srcImage,0,0,0,0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]); }else{ imageCopyResampled($destImage, $srcImage, 0, 0, $offsetX, $offsetY, $destSize[0], $destSize[1], ImagesX($srcImage)-$offsetX, ImagesY($srcImage)-$offsetY); } // generating image switch ($srcSize[2]){ case 1: imageGif($destImage,$dest); break; case 2: imageJpeg($destImage,$dest,$quality); break; case 3: imagePng($destImage,$dest); break; } return true; } else { return false; } }
/** * Закругленные углы * * @param mixed $img дескриптор изображения * @param mixed $cornercolor цвет углов в 16-ной кодировке. Если false - прозрачный * @param mixed $radius радиус закругления * @param mixed $rate сглаживание закругления, максимум - 20 */ private function roundCornersGD(&$img, $cornercolor, $radius = 5, $rate = 5) { if ($radius <= 0) { return false; } if ($rate <= 0) { $rate = 5; } if ($radius > 100) { $radius = 100; } if ($rate > 20) { $rate = 20; } $width = ImagesX($img); $height = ImagesY($img); $radius = $width <= $height ? round($width / 100 * $radius / 2) : round($height / 100 * $radius / 2); $rs_radius = $radius * $rate; $rs_size = $rs_radius * 2; ImageAlphablending($img, false); ImageSaveAlpha($img, true); $corner = ImageCreateTrueColor($rs_size, $rs_size); ImageAlphablending($corner, false); if ($cornercolor === false) { $this->oImg['type'] = IMAGETYPE_PNG; } if ($this->oImg['type'] == IMAGETYPE_PNG) { $trans = ImageColorAllocateAlpha($corner, 255, 255, 255, 127); } else { $trans = ImageColorAllocateAlpha($corner, (int) ($cornercolor % 0x1000000 / 0x10000), (int) ($cornercolor % 0x10000 / 0x100), $cornercolor % 0x100, 0); } imagefilledrectangle($corner, 0, 0, $rs_size, $rs_size, $trans); $positions = array(array(0, 0, 0, 0), array($rs_radius, 0, $width - $radius, 0), array($rs_radius, $rs_radius, $width - $radius, $height - $radius), array(0, $rs_radius, 0, $height - $radius)); foreach ($positions as $pos) { ImageCopyResampled($corner, $img, $pos[0], $pos[1], $pos[2], $pos[3], $rs_radius, $rs_radius, $radius, $radius); } $lx = $ly = 0; $i = -$rs_radius; $y2 = -$i; $r_2 = $rs_radius * $rs_radius; for (; $i <= $y2; $i++) { $y = $i; $x = sqrt($r_2 - $y * $y); $y += $rs_radius; $x += $rs_radius; ImageLine($corner, $x, $y, $rs_size, $y, $trans); ImageLine($corner, 0, $y, $rs_size - $x, $y, $trans); $lx = $x; $ly = $y; } foreach ($positions as $i => $pos) { ImageCopyResampled($img, $corner, $pos[2], $pos[3], $pos[0], $pos[1], $radius, $radius, $rs_radius, $rs_radius); } ImageDestroy($corner); }
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; }
} $tmp = IMAGES_G . md5(time() . $img) . '.tmp'; ImageJPEG($image_tmp, $tmp); ImageDestroy($image_tmp); $image = ImageCreateFromJPEG($tmp); unlink($tmp); } } } $image2 = FALSE; if (file_exists($cop) && strtolower(pathinfo($cop, PATHINFO_EXTENSION)) === 'png' && $gallery_settings['photo_watermark']) { $image_dim_x = ImagesX($image); $image_dim_y = ImagesY($image); $copyright = ImageCreateFromPNG($cop); $copyright_dim_x = ImagesX($copyright); $copyright_dim_y = ImagesY($copyright); $where_x = $image_dim_x - $copyright_dim_x - 5; $where_y = $image_dim_y - $copyright_dim_y - 5; ImageCopy($image, $copyright, $where_x, $where_y, 0, 0, $copyright_dim_x, $copyright_dim_y); $thumb_w = 0; $thumb_h = 0; if (!isset($_GET['full'])) { if ($image_dim_x > $gallery_settings['photo_w'] || $image_dim_y > $gallery_settings['photo_h']) { if ($image_dim_x < $image_dim_y) { $thumb_w = round($image_dim_x * $gallery_settings['photo_h'] / $image_dim_y); $thumb_h = $gallery_settings['photo_h']; } elseif ($image_dim_x > $image_dim_y) { $thumb_w = $gallery_settings['photo_w']; $thumb_h = round($image_dim_y * $gallery_settings['photo_w'] / $image_dim_x); } else { $thumb_w = $gallery_settings['photo_w'];
/** * @desc Esta funcion hace el resamplig de la imagen a los valores maximos * que podra tener la imagen. * No tocar los valores de ancho y alto. */ function Resampling($tmp_name, $directorio, $name) { // Indico el destino del directorio de la imagen if (substr($directorio, -3, 3) != "gif") { $imagen_origen = ImageCreateFromJPEG($directorio); // Calculo el tamaño de la imagen original $tam_ancho = imagesx($imagen_origen); $tam_alto = imagesy($imagen_origen); // Calculo la medida que va a tener // No tocar los valores de Alto y Ancho. if ($tam_ancho >= $tam_alto) { $ancho = 32; $alto = 32; } else { $ancho = 32; $alto = 32; } //Creo una imagen $imagen_destino = ImageCreateTrueColor($ancho, $alto); //Resize imagecopyresized($imagen_destino, $imagen_origen, 0, 0, 0, 0, $ancho, $alto, $tam_ancho, $tam_alto); $nombre_destino = $directorio; //Genero Copia Destino ImageJPEG($imagen_destino, $nombre_destino, 100); //Borro imagen virtual ImageDestroy($imagen_destino); chmod($nombre_destino, 0666); return $ancho; } else { $ancho = 32; $imagen_origen = ImageCreateFromGIF('transparentimage.gif'); $img_width = ImagesX($imagen_origen); $img_height = ImagesY($imagen_origen); /* $new_width = '32'; $new_height = ($new_width * $img_height) / $img_width; */ $imagen_destino = imagecreatetruecolor(32, 32); $colorTransparent = imagecolortransparent($imagen_origen); imagepalettecopy($imagen_origen, $imagen_destino); imagefill($resized, 0, 0, $colorTransparent); imagecolortransparent($imagen_destino, $colorTransparent); imagetruecolortopalette($imagen_destino, true, 256); imagecopyresized($imagen_destino, $imagen_origen, 0, 0, 0, 0, 32, 32, $img_width, $img_height); $nombre_destino = $directorio; ImageDestroy($imagen_destino); /* $imagen_origen = ImageCreateFromGif($directorio); // Calculo el tamaño de la imagen original $tam_ancho = imagesx ($imagen_origen); $tam_alto = imagesy ($imagen_origen); //Calculo la medida que va a tener if ($tam_ancho >= $tam_alto){ $ancho = 32; $alto = 32; }else{ $ancho = 32; $alto = 32; } //Creo una imagen $imagen_destino = ImageCreateTrueColor ($ancho, $alto); //Resize imagecopyresized ($imagen_destino, $imagen_origen, 0,0,0,0, $ancho, $alto, $tam_ancho, $tam_alto); $nombre_destino = $directorio; //Genero Copia Destino imagegif($imagen_destino, $nombre_destino, 100); imagecolortransparent($imagen_destino, $nombre_destino); //Borro imagen virtual ImageDestroy ($imagen_destino); */ chmod($nombre_destino, 0666); return $ancho; } }
require "../php/dbconnect.php"; ob_end_clean(); session_start(); ignore_user_abort(false); // Get working parameters $userno = isset($_SESSION['sp_userno']) ? $userno = $_SESSION['sp_userno'] : ($userno = -5); $gameno = isset($_GET['xgame']) ? $_GET['xgame'] : (isset($_SESSION['sp_gameno']) ? $_SESSION['sp_gameno'] : 0); // Create the image $font = RealPath('../themes/img/verdanab.ttf'); $map = ImageCreateFromPNG('../themes/img/supremacy map.png'); // Find out what size map is required $xsize = isset($_GET['xsize']) ? $_GET['xsize'] : ImagesX($map); if ($xsize <= 200) { $ysize = $xsize; } else { $ysize = ImagesY($map) * $xsize / ImagesX($map); } // Set colours up $white = ImageColorExact($map, 255, 255, 255); $black = ImageColorExact($map, 0, 0, 0); $blue = ImageColorExact($map, 0, 200, 235); $minerals = ImageColorExact($map, 233, 238, 18); $oil = ImageColorExact($map, 254, 0, 254); $grain = ImageColorExact($map, 41, 215, 78); if ($xsize > 200) { $result = $mysqli->query("Select red, green, blue From sp_resource r Left Join sp_powers pw On r.powername=pw.powername Where userno={$userno}"); $row = $result->fetch_assoc(); $result->close(); $powerc = ImageColorExact($map, $row["red"], $row["green"], $row["blue"]); } // Decide how much information is needed for the map
private function cropImg($Image, $Dw, $Dh, $Type = 2) { if ($Type != 1) { $tmp = realpath(APPPATH . '../upload') . '/' . str_replace('.', '_' . $Dw . '.', $Image); $Image = realpath(APPPATH . '../upload') . '/' . $Image; copy($Image, $tmp) or die('error'); $Image = $tmp; } if (!file_exists($Image)) { echo "不存在图片"; return false; } $ImgInfo = getimagesize($Image); switch ($ImgInfo[2]) { case 1: $fn = 'imagegif'; $im = @imagecreatefromgif($Image); break; case 2: $fn = 'imagejpeg'; $im = @imagecreatefromjpeg($Image); break; case 3: $fn = 'imagepng'; $im = @imagecreatefrompng($Image); break; default: echo "格式不支持"; return false; } $w = ImagesX($im); $h = ImagesY($im); $width = $w; $height = $h; if ($width > $Dw) { $Par = $Dw / $width; $width = $Dw; $height = $height * $Par; if ($height > $Dh) { $Par = $Dh / $height; $height = $Dh; $width = $width * $Par; } } elseif ($height > $Dh) { $Par = $Dh / $height; $height = $Dh; $width = $width * $Par; if ($width > $Dw) { $Par = $Dw / $width; $width = $Dw; $height = $height * $Par; } } else { $width = $width; $height = $height; } $nImg = imagecreatetruecolor($width, $height); imagealphablending($nImg, false); imagesavealpha($nImg, true); ImageCopyReSampled($nImg, $im, 0, 0, 0, 0, $width, $height, $w, $h); $fn($nImg, $Image); return true; }
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 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; }
/** * ctreates round corners * @param string destination image key * @param integer radius (0-100) * @param integer rounding quality (1-5) * @return void */ function make_roundcorners($sDestKey, $radius = 5, $rate = 5) { $width = ImagesX($this->img[$sDestKey]); $height = ImagesY($this->img[$sDestKey]); ImageAlphablending($this->img[$sDestKey], false); ImageSaveAlpha($this->img[$sDestKey], true); $rs_radius = $radius * $rate; $rs_size = $rs_radius * 2; $corner = ImageCreateTrueColor($rs_size, $rs_size); ImageAlphablending($corner, false); $trans = ImageColorAllocateAlpha($corner, 255, 255, 255, 127); ImageFill($corner, 0, 0, $trans); $positions = array(array(0, 0, 0, 0), array($rs_radius, 0, $width - $radius, 0), array($rs_radius, $rs_radius, $width - $radius, $height - $radius), array(0, $rs_radius, 0, $height - $radius)); foreach ($positions as $pos) { ImageCopyResampled($corner, $this->img[$sDestKey], $pos[0], $pos[1], $pos[2], $pos[3], $rs_radius, $rs_radius, $radius, $radius); } $lx = $ly = 0; $i = -$rs_radius; $y2 = -$i; $r_2 = $rs_radius * $rs_radius; for (; $i <= $y2; $i++) { $y = $i; $x = sqrt($r_2 - $y * $y); $y += $rs_radius; $x += $rs_radius; ImageLine($corner, $x, $y, $rs_size, $y, $trans); ImageLine($corner, 0, $y, $rs_size - $x, $y, $trans); $lx = $x; $ly = $y; } foreach ($positions as $i => $pos) { ImageCopyResampled($this->img[$sDestKey], $corner, $pos[2], $pos[3], $pos[0], $pos[1], $radius, $radius, $rs_radius, $rs_radius); } ImageDestroy($corner); }
println('Mandatory arguments:'); println(' input the input filename, a JPEG image.'); println(' output filename for saving the changed image.'); println(' scale scale factor, say 0.5 to resize to half the ' . 'original size.'); exit(1); } /* The input file is now loaded into a PelJpeg object. */ println('Reading file "%s".', $input); $input_jpeg = new PelJpeg($input); /* * The input image is already loaded, so we can reuse the bytes stored * in $input_jpeg when creating the Image resource. */ $original = ImageCreateFromString($input_jpeg->getBytes()); $original_w = ImagesX($original); $original_h = ImagesY($original); $scaled_w = $original_w * $scale; $scaled_h = $original_h * $scale; /* Now create the scaled image. */ $scaled = ImageCreateTrueColor($scaled_w, $scaled_h); ImageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h); /* * We want the raw JPEG data from $scaled. Luckily, one can create a * PelJpeg object from an image resource directly: */ $output_jpeg = new PelJpeg($scaled); /* Retrieve the original Exif data in $jpeg (if any). */ $exif = $input_jpeg->getExif(); /* If no Exif data was present, then $exif is null. */ if ($exif != null) { $output_jpeg->setExif($exif);
/** * @param $width * * @return $this */ public function createThumb($width) { $buildcraftThumbsStoragePath = $this->pathBuilderInstance->create()->fromPublicPath(Config::get('blueprint.paths.storage.buildcraft.thumbs')); // Fix Width & Heigh (Auto calculate) $size = getimagesize($this->new_file_path); $height = round($width * $size[1] / $size[0]); $images_orig = imagecreatefromjpeg($this->new_file_path); $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, $buildcraftThumbsStoragePath . $this->file_name . $this->final_file_extension); imagedestroy($images_orig); imagedestroy($images_fin); return $this; }
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); }
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); }
$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}')"); //} } } if ($result_insert) { echo "Success<br>";
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; }
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!"; } }