static function load($filename) { $info = getimagesize($filename); list($width, $height) = $info; if (!$width || !$height) { return null; } $image = null; switch ($info['mime']) { case 'image/gif': $image = imagecreatefromgif($filename); break; case 'image/jpeg': $image = imagecreatefromjpeg($filename); break; case 'image/png': $image = imagecreatetruecolor($width, $height); $white = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $white); $png = imagecreatefrompng($filename); imagealphablending($png, true); imagesavealpha($png, true); imagecopy($image, $png, 0, 0, 0, 0, $width, $height); imagedestroy($png); break; } if ($image) { return new image($image, $width, $height); } else { return null; } }
function upload($tmp, $name, $nome, $larguraP, $pasta) { $ext = strtolower(end(explode('.', $name))); if ($ext == 'jpg') { $img = imagecreatefromjpeg($tmp); } elseif ($ext == 'gif') { $img = imagecreatefromgif($tmp); } else { $img = imagecreatefrompng($tmp); } $x = imagesx($img); $y = imagesy($img); $largura = $x > $larguraP ? $larguraP : $x; $altura = $largura * $y / $x; if ($altura > $larguraP) { $altura = $larguraP; $largura = $altura * $x / $y; } $nova = imagecreatetruecolor($largura, $altura); imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y); imagejpeg($nova, "{$pasta}/{$nome}"); imagedestroy($img); imagedestroy($nova); return $nome; }
function resize($photo_src, $width, $name) { $parametr = getimagesize($photo_src); list($width_orig, $height_orig) = getimagesize($photo_src); $ratio_orig = $width_orig / $height_orig; $new_width = $width; $new_height = $width / $ratio_orig; $newpic = imagecreatetruecolor($new_width, $new_height); $col2 = imagecolorallocate($newpic, 255, 255, 255); imagefilledrectangle($newpic, 0, 0, $new_width, $new_width, $col2); switch ($parametr[2]) { case 1: $image = imagecreatefromgif($photo_src); break; case 2: $image = imagecreatefromjpeg($photo_src); break; case 3: $image = imagecreatefrompng($photo_src); break; } imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); imagejpeg($newpic, $name, 100); return true; }
function GetPartialImage($url) { $W = 150; $H = 130; $F = 80; $STEP = 1.0 / $F; $im = imagecreatefromjpeg($url); $dest = imagecreatetruecolor($W, $H); imagecopy($dest, $im, 0, 0, 35, 40, $W, $H); $a = 1; for( $y = $H - $F; $y < $H; $y++ ) { for ( $x = 0; $x < $W; $x++ ) { $i = imagecolorat($dest, $x, $y); $c = imagecolorsforindex($dest, $i); $c = imagecolorallocate($dest, a($c['red'], $a), a($c['green'], $a), a($c['blue'], $a) ); imagesetpixel($dest, $x, $y, $c); } $a -= $STEP; } header('Content-type: image/png'); imagepng($dest); imagedestroy($dest); imagedestroy($im); }
mkdir($dir . $p, 0755); } } return $p; } private static function _init($file) { $info = getimagesize($file); $method = $im = $ext = null; switch ($info['mime']) { case 'image/jpeg': case 'image/jpg': $ext = '.jpg'; $im = imagecreatefromjpeg($file); $method = 'imagejpeg'; break; case 'image/gif': $ext = '.gif'; $im = imagecreatefromgif($file); $method = 'imagegif'; break; case 'image/png': $ext = '.png'; $im = imagecreatefrompng($file); $method = 'imagepng'; break; case 'image/bmp': $ext = '.bmp'; $im = imagecreatefrombmp($file); $method = 'imagepng'; break;
function background() { $im = imagecreatetruecolor($this->width, $this->height); $bgs = array(); if ($this->style & 8 && function_exists('imagecreatefromjpeg') && function_exists('imagecopymerge')) { if ($fp = @opendir($GLOBALS['imgdir'] . '/ck/bg/')) { while ($flie = @readdir($fp)) { if (preg_match('/\\.jpg$/i', $flie)) { $bgs[] = $GLOBALS['imgdir'] . '/ck/bg/' . $flie; } } @closedir($fp); } } if ($bgs) { $imbg = imagecreatefromjpeg($bgs[array_rand($bgs)]); imagecopymerge($im, $imbg, 0, 0, mt_rand(0, 200 - $this->width), mt_rand(0, 80 - $this->height), $this->width, $this->height, 100); imagedestroy($imbg); } else { $c = array(); for ($i = 0; $i < 3; $i++) { $c[$i] = mt_rand(200, 255); $step[$i] = (mt_rand(100, 150) - $c[$i]) / $this->width; } for ($i = 0; $i < $this->width; $i++) { imageline($im, $i, 0, $i, $this->height, imagecolorallocate($im, $c[0], $c[1], $c[2])); $c[0] += $step[0]; $c[1] += $step[1]; $c[2] += $step[2]; } } return $im; }
private function openImage($file) { // *** Get extension $extension = strtolower(strrchr($file, '.')); //$extension = DataHandler::returnExtensionOfFile($file); switch ($extension) { case '.jpg': case '.jpeg': $img = @imagecreatefromjpeg($file); break; case '.gif': $img = @imagecreatefromgif($file); break; case '.png': $img = @ImageCreateFromPNG($file); // //abaixo do php.net // imagealphablending($img, false); // imagesavealpha($img, true); break; default: $img = false; break; } return $img; }
public function __construct($filepath) { if (!function_exists('gd_info')) { throw new Hayate_Exception(_('GD extension is missing.')); } if (!is_file($filepath)) { throw new Hayate_Exception(sprintf(_('Cannot find %s'), $filepath)); } $this->filepath = $filepath; $info = getimagesize($this->filepath); if (false === $info) { throw new Hayate_Exception(sprintf(_('Cannot read %s'), $filepath)); } list($this->width, $this->height) = $info; $mimes = array('image/jpeg' => 'jpg', 'image/pjpeg' => 'jpg', 'image/gif' => 'gif', 'image/png' => 'png'); $this->ext = isset($mimes[$info['mime']]) ? $mimes[$info['mime']] : null; if (null === $this->ext) { throw new Hayate_Exception(sprintf(_('Supported mime types are: %s'), implode(',', array_keys($mimes)))); } switch ($this->ext) { case 'jpg': $this->img = imagecreatefromjpeg($filepath); break; case 'gif': $this->img = imagecreatefromgif($filepath); break; case 'png': $this->img = imagecreatefrompng($filepath); break; } }
public function cropnsave($id) { $basepath = app_path() . '/storage/uploads/'; $jpeg_quality = 90; $src = $basepath . 'resize_' . $id; if (ImageModel::getImgTypeByExtension($id) == ImageModel::IMGTYPE_PNG) { $img_r = imagecreatefrompng($src); } else { $img_r = imagecreatefromjpeg($src); } $dst_r = ImageCreateTrueColor(Input::get('w'), Input::get('h')); imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), Input::get('w'), Input::get('h'), Input::get('w'), Input::get('h')); $filename = $basepath . 'crop_' . $id; imagejpeg($dst_r, $filename, $jpeg_quality); $image = ImageModel::createImageModel('crop_' . $id); try { $session = Session::get('user'); $userService = new SoapClient(Config::get('wsdl.user')); $currentUser = $userService->getUserById(array("userId" => $session['data']->id)); $currentUser = $currentUser->user; $currentUser->avatar = $image; $result = $userService->updateUser(array("user" => $currentUser)); // Cleanup File::delete($src); File::delete($filename); File::delete($basepath . $id); return Response::json($result->complete); } catch (Exception $ex) { error_log($ex); } }
function create_pic($upfile, $new_path, $width) { $quality = 100; $image_path = $upfile; $image_info = getimagesize($image_path); $exname = ''; //1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF switch ($image_info[2]) { case 1: @($image = imagecreatefromgif($image_path)); $exname = 'gif'; break; case 2: @($image = imagecreatefromjpeg($image_path)); $exname = 'jpg'; break; case 3: @($image = imagecreatefrompng($image_path)); $exname = 'png'; break; case 6: @($image = imagecreatefromwbmp($image_path)); $exname = 'wbmp'; break; } $T_width = $image_info[0]; $T_height = $image_info[1]; if (!empty($image)) { $image_x = imagesx($image); $image_y = imagesy($image); } else { return FALSE; } @chmod($new_path, 0777); if ($image_x > $width) { $x = $width; $y = intval($x * $image_y / $image_x); } else { @copy($image_path, $new_path . '.' . $exname); return $exname; } $newimage = imagecreatetruecolor($x, $y); imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $image_x, $image_y); switch ($image_info[2]) { case 1: imagegif($newimage, $new_path . '.gif', $quality); break; case 2: imagejpeg($newimage, $new_path . '.jpg', $quality); break; case 3: imagepng($newimage, $new_path . '.png', $quality); break; case 6: imagewbmp($newimage, $new_path . '.wbmp', $quality); break; } imagedestroy($newimage); return $exname; }
/** * Load an image * * @param $filename * @return Image * @throws Exception */ public static function load($filename) { $instance = new self(); // Require GD library if (!extension_loaded('gd')) { throw new Exception('Required extension GD is not loaded.'); } $instance->filename = $filename; $info = getimagesize($instance->filename); switch ($info['mime']) { case 'image/gif': $instance->image = imagecreatefromgif($instance->filename); break; case 'image/jpeg': $instance->image = imagecreatefromjpeg($instance->filename); break; case 'image/png': $instance->image = imagecreatefrompng($instance->filename); imagesavealpha($instance->image, true); imagealphablending($instance->image, true); break; default: throw new Exception('Invalid image: ' . $instance->filename); break; } $instance->original_info = array('width' => $info[0], 'height' => $info[1], 'orientation' => $instance->get_orientation(), 'exif' => function_exists('exif_read_data') ? $instance->exif = @exif_read_data($instance->filename) : null, 'format' => preg_replace('/^image\\//', '', $info['mime']), 'mime' => $info['mime']); $instance->width = $info[0]; $instance->height = $info[1]; imagesavealpha($instance->image, true); imagealphablending($instance->image, true); return $instance; }
function get_image($file) { /* Create a resource from image file and return it with getimagesize() array $file - image file or resource return array('res'=>$image_resource, 'imgsize'=>getimagesize($file)) */ if (is_file($file) === true && file_exists($file) === true && is_readable($file) === true) { $img_size = getimagesize($file); if ($img_size !== false) { $im_mime = $img_size['mime']; // Get the image from file if ($im_mime === 'image/jpeg') { $res = imagecreatefromjpeg($file); } else { if ($im_mime === 'image/gif') { $res = imagecreatefromgif($file); } else { if ($im_mime === 'image/png') { $res = imagecreatefrompng($file); } else { // Exit if not supported format return false; } } } return array('res' => $res, 'imgsize' => $img_size); } } return false; }
static function resizewidth($width, $imageold, $imagenew) { $image_info = getimagesize($imageold); $image_type = $image_info[2]; if ($image_type == IMAGETYPE_JPEG) { $image = imagecreatefromjpeg($imageold); } elseif ($this->image_type == IMAGETYPE_GIF) { $image = imagecreatefromgif($imageold); } elseif ($this->image_type == IMAGETYPE_PNG) { $image = imagecreatefrompng($imageold); } $ratio = imagesy($image) / imagesx($image); $height = $width * $ratio; //$width = imagesx($image) * $width/100; // $height = imagesx($image) * $width/100; $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image_info[0], $image_info[1]); $image = $new_image; $compression = 75; $permissions = null; if ($image_type == IMAGETYPE_JPEG) { imagejpeg($image, $imagenew, $compression); } elseif ($image_type == IMAGETYPE_GIF) { imagegif($image, $imagenew); } elseif ($image_type == IMAGETYPE_PNG) { imagepng($image, $imagenew); } if ($permissions != null) { chmod($imagenew, $permissions); } }
function mkthumb($img_src, $img_width = "100", $img_height = "100", $folder_scr = "include/files", $des_src = "include/files") { // Größe und Typ ermitteln list($src_width, $src_height, $src_typ) = getimagesize($folder_scr . "/" . $img_src); if (!$src_typ) { return false; } // calculate new size if ($src_width >= $src_height) { $new_image_height = $src_height / $src_width * $img_width; $new_image_width = $img_width; if ($new_image_height > $img_height) { $new_image_width = $new_image_width / $new_image_height * $img_height; $new_image_height = $img_height; } } else { $new_image_width = $src_width / $src_height * $img_height; $new_image_height = $img_height; if ($new_image_width > $img_width) { $new_image_height = $new_image_height / $new_image_width * $img_width; $new_image_width = $img_width; } } // for the case that the thumbnail would be bigger then the original picture if ($new_image_height > $src_height) { $new_image_width = $new_image_width * $src_height / $new_image_height; $new_image_height = $src_height; } if ($new_image_width > $src_width) { $new_image_height = $new_image_height * $new_image_width / $src_width; $new_image_width = $src_width; } if ($src_typ == 1) { $image = imagecreatefromgif($folder_scr . "/" . $img_src); $new_image = imagecreate($new_image_width, $new_image_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height); imagegif($new_image, $des_src . "/" . $img_src . "_thumb", 100); imagedestroy($image); imagedestroy($new_image); return true; } elseif ($src_typ == 2) { $image = imagecreatefromjpeg($folder_scr . "/" . $img_src); $new_image = imagecreatetruecolor($new_image_width, $new_image_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height); imagejpeg($new_image, $des_src . "/" . $img_src . "_thumb", 100); imagedestroy($image); imagedestroy($new_image); return true; } elseif ($src_typ == 3) { $image = imagecreatefrompng($folder_scr . "/" . $img_src); $new_image = imagecreatetruecolor($new_image_width, $new_image_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_image_width, $new_image_height, $src_width, $src_height); imagepng($new_image, $des_src . "/" . $img_src . "_thumb"); imagedestroy($image); imagedestroy($new_image); return true; } else { return false; } }
/** * Set the image variable by using image create * * @param string $filename - The image filename */ private function setImage($filename) { $size = getimagesize($filename); $this->ext = $size['mime']; switch ($this->ext) { // Image is a JPG case 'image/jpg': case 'image/jpeg': // create a jpeg extension $this->image = imagecreatefromjpeg($filename); break; // Image is a GIF // Image is a GIF case 'image/gif': $this->image = @imagecreatefromgif($filename); break; // Image is a PNG // Image is a PNG case 'image/png': $this->image = @imagecreatefrompng($filename); break; // Mime type not found // Mime type not found default: throw new Exception("File is not an image, please use another file type.", 1); } $this->origWidth = imagesx($this->image); $this->origHeight = imagesy($this->image); }
private function openImage($file) { // *** Get extension $extension = strtolower(strrchr($file, '.')); $file_size = @filesize($file) / 1024 / 1024; // magic number convert bytes to mb $image_size_limit = 0.5; // sorry for the magic numbering... can't get a good read on how to programatically fix this. // if we're about to try to load a massive image... // don't if ($file_size >= $image_size_limit || $file_size == 0) { return false; } switch ($extension) { case '.jpg': case '.jpeg': $img = imagecreatefromjpeg($file); break; case '.gif': $img = @imagecreatefromgif($file); break; case '.png': $img = @imagecreatefrompng($file); break; default: $img = false; break; } return $img; }
public function save() { $maxHeight = 0; $width = 0; foreach ($this->_segmentsArray as $segment) { $maxHeight = max($maxHeight, $segment->height); $width += $segment->width; } // create our canvas $img = imagecreatetruecolor($width, $maxHeight); $background = imagecolorallocatealpha($img, 255, 255, 255, 127); imagefill($img, 0, 0, $background); imagealphablending($img, false); imagesavealpha($img, true); // start placing our images on a single x axis $xPos = 0; foreach ($this->_segmentsArray as $segment) { $tmp = imagecreatefromjpeg($segment->pathToImage); imagecopy($img, $tmp, $xPos, 0, 0, 0, $segment->width, $segment->height); $xPos += $segment->width; imagedestroy($tmp); } // create our final output image. imagepng($img, $this->_saveToPath); }
function _thumb($_filename, $_percent) { //生成png标头文件 header('Content-type: image/png'); $_n = explode('.', $_filename); //获取文件信息,长和高 list($_width, $_height) = getimagesize($_filename); //生成缩微的长和高 $_new_width = $_width * $_percent; $_new_height = $_height * $_percent; //创建一个以0.3百分比新长度的画布 $_new_image = imagecreatetruecolor($_new_width, $_new_height); //按照已有的图片创建一个画布 switch ($_n[1]) { case 'jpg': $_image = imagecreatefromjpeg($_filename); break; case 'png': $_image = imagecreatefrompng($_filename); break; case 'gif': $_image = imagecreatefrompng($_filename); break; } //将原图采集后重新复制到新图上,就缩略了 imagecopyresampled($_new_image, $_image, 0, 0, 0, 0, $_new_width, $_new_height, $_width, $_height); imagepng($_new_image); imagedestroy($_new_image); imagedestroy($_image); }
/** * MÉTODO CONSTRUTOR * * @author Gibran */ function Imagem($arquivo) { if (is_file($arquivo)) { $this->Arquivo = $arquivo; // OBTÉM OS DADOS DA IMAGEM $this->ColecaoDados = getimagesize($this->Arquivo); // CARREGA A IMAGEM DE ACORDO COM O TIPO switch ($this->ColecaoDados[2]) { case 1: $this->Recurso = imagecreatefromgif($this->Arquivo); $this->Tipo = "image/gif"; break; case 2: $this->Recurso = imagecreatefromjpeg($this->Arquivo); $this->Tipo = "image/jpeg"; imageinterlace($this->Recurso, true); break; case 3: $this->Recurso = imagecreatefrompng($this->Arquivo); $this->Tipo = "image/png"; imagealphablending($this->Recurso, false); imagesavealpha($this->Recurso, true); break; default: $this->ColecaoDados = null; $this->Recurso = null; $this->Tipo = null; return null; break; } } else { return null; } }
/** Returns an array. Element 0 - GD resource. Element 1 - width. Element 2 - height. * Returns FALSE on failure. The only one parameter $image can be an instance of this class, * a GD resource, an array(width, height) or path to image file. * @param mixed $image * @return array */ protected function build_image($image) { if ($image instanceof gd) { $width = $image->get_width(); $height = $image->get_height(); $image = $image->get_image(); } elseif (is_resource($image) && get_resource_type($image) == "gd") { $width = @imagesx($image); $height = @imagesy($image); } elseif (is_array($image)) { list($key, $width) = each($image); list($key, $height) = each($image); $image = imagecreatetruecolor($width, $height); } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) { $image = $type == IMAGETYPE_GIF ? @imagecreatefromgif($image) : ($type == IMAGETYPE_WBMP ? @imagecreatefromwbmp($image) : ($type == IMAGETYPE_JPEG ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_JPEG2000 ? @imagecreatefromjpeg($image) : ($type == IMAGETYPE_PNG ? imagecreatefrompng($image) : ($type == IMAGETYPE_XBM ? @imagecreatefromxbm($image) : false))))); if ($type == IMAGETYPE_PNG) { imagealphablending($image, false); } } $return = is_resource($image) && get_resource_type($image) == "gd" && isset($width) && isset($height) && preg_match('/^[1-9][0-9]*$/', $width) !== false && preg_match('/^[1-9][0-9]*$/', $height) !== false ? array($image, $width, $height) : false; if ($return !== false && isset($type)) { $this->type = $type; } return $return; }
public function __construct($path) { if (!file_exists($path)) { throw new Exception("Данного файла нет"); } $this->type = $this->getType($path); switch ($this->type) { case IMAGETYPE_JPEG: $img = imagecreatefromjpeg($path); break; case IMAGETYPE_PNG: $img = imagecreatefrompng($path); break; case IMAGETYPE_PNG: $img = imagecreatefrompng($path); break; case IMAGETYPE_BMP: $img = imagecreatefromwbmp($path); break; default: $img = false; } $this->img = $img; if (!$this->img) { throw new Exception('Не удалость создать дескриптор изображения'); } $this->width = imagesx($this->img); $this->height = imagesy($this->img); }
function UploadImage($bukti_name) { //direktori gambar $vdir_upload = "bukti/"; $vfile_upload = $vdir_upload . $bukti_name; //Simpan gambar dalam ukuran sebenarnya move_uploaded_file($_FILES["bukti"]["tmp_name"], $vfile_upload); //identitas file asli $im_src = imagecreatefromjpeg($vfile_upload); $src_width = imageSX($im_src); $src_height = imageSY($im_src); //Simpan dalam versi small 110 pixel //Set ukuran gambar hasil perubahan $dst_width = 50; $dst_height = $dst_width / $src_width * $src_height; //proses perubahan ukuran $im = imagecreatetruecolor($dst_width, $dst_height); imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); //Simpan gambar imagejpeg($im, $vdir_upload . "small_" . $bukti_name); //Simpan dalam versi medium 360 pixel //Set ukuran gambar hasil perubahan $dst_width2 = 270; $dst_height2 = $dst_width2 / $src_width * $src_height; //proses perubahan ukuran $im2 = imagecreatetruecolor($dst_width2, $dst_height2); imagecopyresampled($im2, $im_src, 0, 0, 0, 0, $dst_width2, $dst_height2, $src_width, $src_height); //Simpan gambar imagejpeg($im2, $vdir_upload . "medium_" . $bukti_name); //Hapus gambar di memori komputer imagedestroy($im_src); imagedestroy($im); imagedestroy($im2); }
function hacknrollify($picfilename) { $logofilename = "logo.png"; $logoPicPath = "logopics/" . $logofilename; $originalPicPath = "originalpics/" . $picfilename; $editedfilename = "hnr_" . $picfilename; $editedPicPath = "editedpics/" . $editedfilename; // read the original image from file $profilepic = imagecreatefromjpeg($originalPicPath); $profilepicWidth = imagesx($profilepic); $profilepicHeight = imagesy($profilepic); // create the black image overlay $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight); imagecolorallocate($blackoverlay, 0, 0, 0); // then merge the black and profilepic imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50); imagedestroy($blackoverlay); // merge the resized logo $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999); imageAlphaBlending($logo, false); imageSaveAlpha($logo, true); $logoWidth = imagesx($logo); $logoHeight = imagesy($logo); $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2; $horizontalOffset = 40; imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight); $mergeSuccess = imagejpeg($profilepic, $editedPicPath); if (!$mergeSuccess) { echo "Image merge failed!"; } imagedestroy($profilepic); imagedestroy($logo); return $editedPicPath; }
/** * Retourne la couleur du pixel en bas a gauche de l'image **/ function colorImageBottom($imageName) { // recuperer le type et la taille de l'image // Pb sur certains JPG qui retourne '' list($imgW, $imgH, $imgTyp) = getimagesize($imageName); switch ($imgTyp) { case 1: $im = imagecreatefromgif($imageName); break; case 2: case ' ': $im = imagecreatefromjpeg($imageName); break; case 3: $im = imagecreatefrompng($imageName); break; default: $app = JFactory::getApplication(); $app->enqueueMessage(JTEXT::_('IMGNAME_ERROR') . '[name=' . $imageName . '] [ type=' . $imgTyp . '] [ format= ' . $imgW . 'x' . $imgH, 'error'); var_dump(gd_info()); return ""; } $rgb = imagecolorat($im, 2, $imgH - 2); $hex = sprintf("%06X", $rgb); return $hex; }
public function fill_watermark() { $image = $this->editor->get_image(); $size = $this->editor->get_size(); list($mask_width, $mask_height, $mask_type, $mask_attr) = getimagesize($this->args['mask']); switch ($mask_type) { case 1: $mask = imagecreatefromgif($this->args['mask']); break; case 2: $mask = imagecreatefromjpeg($this->args['mask']); break; case 3: $mask = imagecreatefrompng($this->args['mask']); break; } imagealphablending($image, true); if (strpos($this->args['position'], 'left') !== false) { $left = $this->args['padding']; } else { $left = $size['width'] - $mask_width - $this->args['padding']; } if (strpos($this->args['position'], 'top') !== false) { $top = $this->args['padding']; } else { $top = $size['height'] - $mask_height - $this->args['padding']; } imagecopy($image, $mask, $left, $top, 0, 0, $mask_width, $mask_height); $this->editor->update_image($image); imagedestroy($mask); }
private function createnewpicture() { $local = $this->path_two . $this->file['name']; move_uploaded_file($this->file['tmp_name'], $local); $filename = $this->file['tmp_name'] . "/" . $this->file['name']; $this->location = $this->path . "/" . $this->file['name']; switch ($this->file['type']) { case 'image/jpeg': $src = imagecreatefromjpeg($local); break; case 'image/png': $src = imagecreatefrompng($local); break; case 'image/gif': $src = imagecreatefromgif($local); break; default: break; } $sx = imagesx($src); $sy = imagesy($src); $new_image = imagecreatetruecolor($this->newwidth, $this->newheight); if (imagecopyresized($new_image, $src, 0, 0, 0, 0, $this->newwidth, $this->newheight, $sx, $sy)) { if (ImageJpeg($new_image, $this->location) || Imagegif($new_image, $this->location) || Imagepng($new_image, $this->location)) { //imagejpeg($this->location); return true; } } else { return false; } }
function createthumb($originalImage, $new_w, $new_h) { $src_img = imagecreatefromjpeg("uploads/" . $originalImage); # Add the _t to our image name list($imageName, $extension) = explode(".", $originalImage); $newName = $imageName . "_t." . $extension; # Maintain proportions $old_x = imageSX($src_img); $old_y = imageSY($src_img); if ($old_x > $old_y) { $thumb_w = $new_w; $thumb_h = $old_y * ($new_h / $old_x); } if ($old_x < $old_y) { $thumb_w = $old_x * ($new_w / $old_y); $thumb_h = $new_h; } if ($old_x == $old_y) { $thumb_w = $new_w; $thumb_h = $new_h; } # Create destination-image-resource $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); # Copy source-image-resource to destination-image-resource imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); # Create the final image from the destination-image-resource imagejpeg($dst_img, "uploads/" . $newName); # Delete our image-resources imagedestroy($dst_img); imagedestroy($src_img); # Show results return $newName; }
public function getDomiColor($url) { \application\resonance2\debug\console::FunctionTrace(__FUNCTION__); $i = imagecreatefromjpeg($url); $rTotal = ''; $bTotal = ''; $gTotal = ''; $total = ''; for ($x = 0; $x < imagesx($i); $x++) { for ($y = 0; $y < imagesy($i); $y++) { $rgb = imagecolorat($i, $x, $y); $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; $rTotal += $r; $gTotal += $g; $bTotal += $b; $total++; } } $r = round($rTotal / $total); $g = round($gTotal / $total); $b = round($bTotal / $total); $rgb = array($r, $g, $b); return $rgb; }
function _qmd_img_list($pic_path = '', $user_uid = 0, $user_face = '', $topic_content = '', $topic_dateline) { header("Content-type: image/png"); $bg = imagecreatefromjpeg($pic_path); $white = imagecolorallocate($bg, 00, 00, 00); $content = str_split($topic_content, 40); $content = array_iconv($this->Config['charset'], 'utf-8', $content); $topic_url = $this->Config['site_url']; $topic_date = array_iconv($this->Config['charset'], 'utf-8', $topic_dateline . ' | ' . '记事狗微博'); imagettftext($bg, 9, 0, 130, 25, $white, "images/simsun.ttc", $content[0]); imagettftext($bg, 9, 0, 130, 45, $white, "images/simsun.ttc", $content[1]); imagettftext($bg, 9, 0, 130, 70, $white, "images/simsun.ttc", $topic_date); imagettftext($bg, 9, 0, 218, 90, $white, "images/simsun.ttc", $topic_url); $dst_im = imagecreatefromjpeg($bg); $dst_info = getimagesize($bg); $src = $user_face; $src_im = imagecreatefromjpeg($src); $src_info = getimagesize($src); $dst_x = 20; $dst_y = 12; $src_x = 0; $src_y = 0; $src_w = $src_info[0]; $src_h = $src_info[1]; $alpha = 100; imagecopymerge($bg, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $alpha); $image_path = RELATIVE_ROOT_PATH . 'images/qmd/' . face_path(MEMBER_ID); if (!is_dir($image_path)) { jio()->MakeDir($image_path); } $image_file = $image_path . MEMBER_ID . '_o.png'; imagepng($bg, $image_file); imagedestroy($bg); return $image_file; }
function resizer($image) { $name = md5(sha1(date('d-m-y H:i:s') . $image['tmp_name'])); $type = $image['type']; switch ($type) { case "image/jpeg": $img = imagecreatefromjpeg($image['tmp_name']); break; case "image/png": $img = imagecreatefrompng($image['tmp_name']); break; } $x = imagesx($img); $y = imagesy($img); $height = 1200 * $y / $x; $new = imagecreatetruecolor(1200, $height); imagecopyresampled($new, $img, 0, 0, 0, 0, 1200, $height, $x, $y); switch ($type) { case "image/jpeg": $local = "../assets/img/Portfolioimg/{$name}" . ".jpg"; imagejpeg($new, $local); break; case "image/png": $local = "../assets/img/Portfolioimg/{$name}" . ".png"; imagejpeg($new, $local); break; } return $local; }