private function getImage() { $image = imagecreatefromstring(file_get_contents($this->file['tmp_name'])); if ($this->currentExtension == 'jpg' || $this->currentExtension == 'jpeg') { $exif = exif_read_data($this->file['tmp_name']); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: $image = imagerotate($image, 90, 0); break; case 3: $image = imagerotate($image, 180, 0); break; case 6: $image = imagerotate($image, -90, 0); break; } } } // Get new sizes $width = imagesx($image); $height = imagesy($image); //list($width, $height) = getimagesize($this->file['tmp_name']); list($newWidth, $newHeight) = $this->getScaledDimArray($image, 800); // Load $resizeImage = imagecreatetruecolor($newWidth, $newHeight); // Resize imagecopyresized($resizeImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); return $resizeImage; }
private static function set_img() { self::$res_img = imagecreatetruecolor(self::$width, self::$height); $color_bg = imagecolorallocate(self::$res_img, 255, 255, 255); //填充图片 imagefilledrectangle(self::$res_img, 0, self::$height, self::$width, 0, $color_bg); }
/** * Background fill an image using the provided color * * @param int $width The desired width of the new image * @param int $height The desired height of the new image * @param Array the desired pad colors in RGB format, array should be array( 'top' => '', 'right' => '', 'bottom' => '', 'left' => '' ); */ private function fill_color(array $colors) { $current_size = $this->editor->get_size(); $size = array('width' => $this->args['width'], 'height' => $this->args['height']); $offsetLeft = ($size['width'] - $current_size['width']) / 2; $offsetTop = ($size['height'] - $current_size['height']) / 2; $new_image = imagecreatetruecolor($size['width'], $size['height']); // This is needed to support alpha imagesavealpha($new_image, true); imagealphablending($new_image, false); // Check if we are padding vertically or horizontally if ($current_size['width'] != $size['width']) { $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['left'], 0, 3), substr($colors['left'], 3, 3), substr($colors['left'], 6, 3), substr($colors['left'], 9, 3)); // Fill left color imagefilledrectangle($new_image, 0, 0, $offsetLeft + 5, $size['height'], $colorToPaint); $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['right'], 0, 3), substr($colors['right'], 3, 3), substr($colors['right'], 6, 3), substr($colors['left'], 9, 3)); // Fill right color imagefilledrectangle($new_image, $offsetLeft + $current_size['width'] - 5, 0, $size['width'], $size['height'], $colorToPaint); } elseif ($current_size['height'] != $size['height']) { $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['top'], 0, 3), substr($colors['top'], 3, 3), substr($colors['top'], 6, 3), substr($colors['left'], 9, 3)); // Fill top color imagefilledrectangle($new_image, 0, 0, $size['width'], $offsetTop + 5, $colorToPaint); $colorToPaint = imagecolorallocatealpha($new_image, substr($colors['bottom'], 0, 3), substr($colors['bottom'], 3, 3), substr($colors['bottom'], 6, 3), substr($colors['left'], 9, 3)); // Fill bottom color imagefilledrectangle($new_image, 0, $offsetTop - 5 + $current_size['height'], $size['width'], $size['height'], $colorToPaint); } imagecopy($new_image, $this->editor->get_image(), $offsetLeft, $offsetTop, 0, 0, $current_size['width'], $current_size['height']); $this->editor->update_image($new_image); $this->editor->update_size(); }
function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = false, $scale = 0.5) { list($src_w, $src_h, $imagetype) = getimagesize($filename); if (is_null($dst_w) || is_null($dst_h)) { $dst_w = ceil($src_w * $scale); $dst_h = ceil($src_h * $scale); } $mime = image_type_to_mime_type($imagetype); $createFun = str_replace("/", "createfrom", $mime); $outFun = str_replace("/", null, $mime); $src_image = $createFun($filename); $dst_image = imagecreatetruecolor($dst_w, $dst_h); imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h); //image_50/sdfsdkfjkelwkerjle.jpg if ($destination && !file_exists(dirname($destination))) { mkdir(dirname($destination), 0777, true); } $dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination; $outFun($dst_image, $dstFilename); imagedestroy($src_image); imagedestroy($dst_image); if (!$isReservedSource) { unlink($filename); } return $dstFilename; }
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; } }
public function init(awImage $image) { if ($this->resource === NULL) { $this->setImageSize($image->width, $image->height); // Create image $this->resource = imagecreatetruecolor($this->imageWidth, $this->imageHeight); if (!$this->resource) { awImage::drawError("Class Image: Unable to create a graph."); } imagealphablending($this->resource, TRUE); // Antialiasing is now handled by the Driver object $this->setAntiAliasing($image->getAntiAliasing()); // Original color $this->filledRectangle(new awWhite(), new awLine(new awPoint(0, 0), new awPoint($this->imageWidth, $this->imageHeight))); $shadow = $image->shadow; if ($shadow !== NULL) { $shadow = $shadow->getSpace(); $p1 = new awPoint($shadow->left, $shadow->top); $p2 = new awPoint($this->imageWidth - $shadow->right - 1, $this->imageHeight - $shadow->bottom - 1); // Draw image background $this->filledRectangle($image->getBackground(), new awLine($p1, $p2)); // Draw image border $image->border->rectangle($this, $p1, $p2); } } }
function fastimagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) { // Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled. // Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled". // Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting. // Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely distributable - These comments must remain. // // Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example // 1.5. Must be greater than zero. // Between 0 and 1 = Fast, but mosaic results, closer to 0 increases the mosaic effect. // 1 = Up to 350 times faster. Poor results, looks very similar to imagecopyresized. // 2 = Up to 95 times faster. Images appear a little sharp, some prefer this over a quality of 3. // 3 = Up to 60 times faster. Will give high quality smooth results very close to imagecopyresampled, just faster. // 4 = Up to 25 times faster. Almost identical to imagecopyresampled for most images. // 5 = No speedup. Just uses imagecopyresampled, no advantage over imagecopyresampled. if (empty($src_image) || empty($dst_image) || $quality <= 0) { return false; } if ($quality < 5 && ($dst_w * $quality < $src_w || $dst_h * $quality < $src_h)) { $temp = imagecreatetruecolor($dst_w * $quality + 1, $dst_h * $quality + 1); imagecopyresized($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h * $quality + 1, $src_w, $src_h); imagecopyresampled($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality, $dst_h * $quality); imagedestroy($temp); } else { imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } return true; }
function DrawGraph($file = "") { $this->graph_width = $this->graph_padding['left'] + count($this->data) * ($this->bar_width + $this->bar_padding * 2) + $this->graph_padding['right']; $this->axis_deepness = $this->bar_height; $this->im = imagecreatetruecolor($this->graph_width, $this->graph_height); $this->axis_frontgridlines = 0; $this->axis_xscalevisible = 0; $this->axis_positions = array($this->axis_positions[0], 0, 0, 0); CGraph::DrawGraph(); if ($this->axis_minY > 0) { $this->axis_minY = 0; } if ($this->axis_maxY < 0) { $this->axis_maxY = 0; } $this->__Draw_LeftBottom_Axis(); $p = 0; foreach ($this->data as $name => $value) { $p++; $this->__DrawBarText($p, $name); $this->__DrawBar($p, $value); } $this->__Draw_TopRight_Axis(); CGraph::DrawGraph2(); if (strlen($file)) { $ret = imagepng($this->im, $file); } else { header("Content-Type: image/png"); // thanks to Marcin G. :) imagepng($this->im); $ret = true; } imagedestroy($this->im); return $ret; }
static function codeimage() { $image = imagecreatetruecolor(100, 30); $bgcolor = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $bgcolor); $code = ''; for ($i = 0; $i < 4; $i++) { $fontsize = 6; $fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120)); $data = "abcdefghjkmnpqrstuvwxy3456789"; $fontcontent = substr($data, rand(1, strlen($data) - 1), 1); $code .= $fontcontent; $x = $i * 100 / 4 + rand(5, 10); $y = rand(5, 10); imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor); } for ($i = 0; $i < 200; $i++) { $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200)); imagesetpixel($image, rand(1, 99), rand(1, 29), $pointcolor); } for ($i = 0; $i < 2; $i++) { $linecolor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220)); imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $linecolor); } $return['code'] = $code; $return['image'] = $image; return $return; // header('content-type:image/png'); // imagepng($image); }
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; }
public function resizeTo($width, $height) { if (osc_use_imagick()) { $bg = new Imagick(); $bg->newImage($width, $height, 'white'); $this->im->thumbnailImage($width, $height, true); $geometry = $this->im->getImageGeometry(); $x = ($width - $geometry['width']) / 2; $y = ($height - $geometry['height']) / 2; $bg->compositeImage($this->im, imagick::COMPOSITE_OVER, $x, $y); $this->im = $bg; } else { $w = imagesx($this->im); $h = imagesy($this->im); if ($w / $h >= $width / $height) { //$newW = $width; $newW = $w > $width ? $width : $w; $newH = $h * ($newW / $w); } else { //$newH = $height; $newH = $h > $height ? $height : $h; $newW = $w * ($newH / $h); } $newIm = imagecreatetruecolor($width, $height); //$newW, $newH); imagealphablending($newIm, false); $colorTransparent = imagecolorallocatealpha($newIm, 255, 255, 255, 127); imagefill($newIm, 0, 0, $colorTransparent); imagesavealpha($newIm, true); imagecopyresampled($newIm, $this->im, ($width - $newW) / 2, ($height - $newH) / 2, 0, 0, $newW, $newH, $w, $h); imagedestroy($this->im); $this->im = $newIm; } return $this; }
public static function create() { $image = imagecreatetruecolor(100, 40) or die('cannot create canvas.<br>'); $red = imagecolorallocate($image, 255, 0, 0); $green = imagecolorallocate($image, 0, 255, 0); $blue = imagecolorallocate($image, 0, 0, 255); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); imagefill($image, 0, 0, $white); imagerectangle($image, 1, 1, 99, 39, $black); $color = [$red, $green, $blue]; for ($i = 1; $i <= 100; $i++) { imagesetpixel($image, mt_rand(2, 98), mt_rand(2, 38), $color[mt_rand(0, 2)]); } $source = "abcdefghigklmnopqrstuvwxyz0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ"; $first = $source[mt_rand(0, 61)]; $second = $source[mt_rand(0, 61)]; $third = $source[mt_rand(0, 61)]; $fourth = $source[mt_rand(0, 61)]; $_SESSION['captcha'] = $first . $second . $third . $fourth; $font = dirname(dirname(__DIR__)) . '/../public/assets/fonts/SpicyRice.ttf'; imagettftext($image, 20, mt_rand(-20, 20), 10, 30, $blue, $font, $first); imagettftext($image, 20, mt_rand(-20, 20), 30, 30, $blue, $font, $second); imagettftext($image, 20, mt_rand(-20, 20), 50, 30, $blue, $font, $third); imagettftext($image, 20, mt_rand(-20, 20), 70, 30, $blue, $font, $fourth); return imagejpeg($image); }
/** * Cria a imagem apartir dos dados do Sprite. */ public function createImage() { $img = imagecreatetruecolor($this->width, $this->height); //http://in.php.net/manual/en/function.imagecreatetruecolor.php imagecolortransparent($img, imagecolorallocatealpha($img, $this->palette[0]['red'], $this->palette[0]['green'], $this->palette[0]['blue'], $this->palette[0]['alpha'])); $i = 0; $p = 0; while ($i < strlen($this->data)) { $b = ord($this->data[$i]); //http://in.php.net/manual/en/function.ord.php if ($b == 0) { $i++; $dest = $p + ord($this->data[$i]); $color = imagecolorallocatealpha($img, $this->palette[0]['red'], $this->palette[0]['green'], $this->palette[0]['blue'], $this->palette[0]['alpha']); //http://in.php.net/manual/en/function.imagecolorallocatealpha.php for ($p; $p < $dest; $p++) { imagesetpixel($img, $p % $this->width, $p / $this->width, $color); } } else { $color = imagecolorallocatealpha($img, $this->palette[$b]['red'], $this->palette[$b]['green'], $this->palette[$b]['blue'], $this->palette[$b]['alpha']); imagesetpixel($img, $p % $this->width, $p / $this->width, $color); //http://in.php.net/manual/en/function.imagesetpixel.php $p++; } $i++; } return $img; }
/** * Resizes the given image resource to the specified size keeping the original * proportions of the image. * * @param resource $source * @param int $thumbWidth * @param int $thumbHeight * * @return resource */ function imageThumb($source, $thumbWidth = 0, $thumbHeight = 0) { $srcWidth = imagesx($source); $srcHeight = imagesy($source); if ($srcWidth > $thumbWidth || $srcHeight > $thumbHeight) { if ($thumbWidth == 0) { $thumbWidth = $thumbHeight * $srcWidth / $srcHeight; } elseif ($thumbHeight == 0) { $thumbHeight = $thumbWidth * $srcHeight / $srcWidth; } else { $a = $thumbWidth / $thumbHeight; $b = $srcWidth / $srcHeight; if ($a > $b) { $thumbWidth = $b * $thumbHeight; } else { $thumbHeight = $thumbWidth / $b; } } if (function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) { $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight); } else { $thumb = imagecreate($thumbWidth, $thumbHeight); } // preserve png transparency imagealphablending($thumb, false); imagesavealpha($thumb, true); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight); imagedestroy($source); $source = $thumb; } return $source; }
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; } }
function embroidery2image($embroidery, $scale_post = 1, $scale_pre = false) { // Create image $im = imagecreatetruecolor(ceil($embroidery->imageWidth * $scale_post), ceil($embroidery->imageHeight * $scale_post)); imagesavealpha($im, true); imagealphablending($im, false); $color = imagecolorallocatealpha($im, 255, 255, 255, 127); imagefill($im, 0, 0, $color); // Draw stitches foreach ($embroidery->blocks as $block) { $color = imagecolorallocate($im, $block->color->r, $block->color->g, $block->color->b); $x = false; foreach ($block->stitches as $stitch) { if ($x !== false) { imageline($im, ($x - $embroidery->min->x) * $scale_post, ($y - $embroidery->min->y) * $scale_post, ($stitch->x - $embroidery->min->x) * $scale_post, ($stitch->y - $embroidery->min->y) * $scale_post, $color); } $x = $stitch->x; $y = $stitch->y; } } // Scale finished image if ($scale_pre) { $im2 = imagecreatetruecolor($embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre); imagesavealpha($im2, true); imagealphablending($im2, false); imagecopyresized($im2, $im, 0, 0, 0, 0, $embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre, $embroidery->imageWidth * $scale_post, $embroidery->imageHeight * $scale_post); imagedestroy($im); $im = $im2; } return $im; }
function foundation_process_image_file($file_name, $setting_name) { if ($setting_name->domain == FOUNDATION_SETTING_DOMAIN && $setting_name->name == 'logo_image') { // Need to make sure this isn't too big if (function_exists('getimagesize') && function_exists('imagecreatefrompng') && function_exists('imagecopyresampled') && function_exists('imagepng')) { $size = getimagesize($file_name); if ($size) { $width = $size[0]; $height = $size[1]; if ($size['mime'] == 'image/png') { if ($width > FOUNDATION_MAX_LOGO_SIZE) { $new_width = FOUNDATION_MAX_LOGO_SIZE; $new_height = $height * $new_width / $width; $src_image = imagecreatefrompng($file_name); $saved_image = imagecreatetruecolor($new_width, $new_height); // Preserve Transparency imagecolortransparent($saved_image, imagecolorallocate($saved_image, 0, 0, 0)); imagecopyresampled($saved_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Get rid of the old file unlink($file_name); // New image, compression level 5 (make it a bit smaller) imagepng($saved_image, $file_name, 5); } } } } } }
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 max_height($a_max) { $max = intval($a_max) * ($this->m_width / $this->m_height); $dst = imagecreatetruecolor($max, intval($a_max)); imagecopyresampled($dst, $this->m_handle, 0, 0, 0, 0, $max, intval($a_max), $this->m_width, $this->m_height); $this->set($dst); }
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; }
/** * Return label image for product * @param <type> $productId */ public function getImage($productId) { $product = Mage::getModel('catalog/product')->load($productId); //create base image $labelSize = Mage::helper('BarcodeLabel')->getlabelSize(); $height = $labelSize['height'] * $this->_coef; $width = $labelSize['width'] * $this->_coef; $im = imagecreatetruecolor($width, $height); $white = imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im, 0, 0, $width, $height, $white); //add barcode $this->addBarcode($im, $product); //add product name $this->addName($im, $product); //add product attributes $this->addProductAttributes($im, $product); //add manufacturer $this->addManufacturer($im, $product); //add logo $this->addLogo($im); // add product image $this->addProductPicture($im, $product); //add product sku $this->addSku($im, $product); //add price $this->addPrice($im, $product); //add price $this->addCustoms($im, $product); //return image return $im; }
function background() { $this->im = imagecreatetruecolor($this->width, $this->height); $backgrounds = $c = array(); if (!$this->background || !$backgrounds) { for ($i = 0; $i < 3; $i++) { $start[$i] = mt_rand(200, 255); $end[$i] = mt_rand(100, 150); $step[$i] = ($end[$i] - $start[$i]) / $this->width; $c[$i] = $start[$i]; } for ($i = 0; $i < $this->width; $i++) { $color = imagecolorallocate($this->im, $c[0], $c[1], $c[2]); imageline($this->im, $i, 0, $i, $this->height, $color); $c[0] += $step[0]; $c[1] += $step[1]; $c[2] += $step[2]; } $c[0] -= 20; $c[1] -= 20; $c[2] -= 20; } ob_start(); if (function_exists('imagepng')) { imagepng($this->im); } else { imagejpeg($this->im, '', 100); } imagedestroy($this->im); $bgcontent = ob_get_contents(); ob_end_clean(); $this->fontcolor = $c; return $bgcontent; }
function cuttingimg($zoom, $fn, $sz) { @mkdir(WUO_ROOT . '/photos/maps'); $img = imagecreatefrompng(WUO_ROOT . '/photos/maps/0-0-0-' . $fn); // получаем идентификатор загруженного изрбражения которое будем резать $info = getimagesize(WUO_ROOT . '/photos/maps/0-0-0-' . $fn); // получаем в массив информацию об изображении $w = $info[0]; $h = $info[1]; // ширина и высота исходного изображения $sx = round($w / $sz, 0); // длинна куска изображения $sy = round($h / $sz, 0); // высота куска изображения $px = 0; $py = 0; // координаты шага "реза" for ($y = 0; $y <= $sz; $y++) { for ($x = 0; $x <= $sz; $x++) { $imgcropped = imagecreatetruecolor($sx, $sy); imagecopy($imgcropped, $img, 0, 0, $px, $py, $sx, $sy); imagepng($imgcropped, WUO_ROOT . '/photos/maps/' . $zoom . '-' . $y . '-' . $x . '-' . $fn); $px = $px + $sx; } $px = 0; $py = $py + $sy; } }
/** * Generate and display the CAPTCHA image. * @param $captcha object Captcha */ function generateImage(&$captcha) { $width = $this->getWidth(); $height = $this->getHeight(); $length = String::strlen($captcha->getValue()); $value = $captcha->getValue(); $image = imagecreatetruecolor($width, $height); $fg = imagecolorallocate($image, rand(128, 255), rand(128, 255), rand(128, 255)); $bg = imagecolorallocate($image, rand(0, 64), rand(0, 64), rand(0, 64)); imagefill($image, $width / 2, $height / 2, $bg); $xStart = rand($width / 12, $width / 3); $xEnd = rand($width * 2 / 3, $width * 11 / 12); for ($i = 0; $i < $length; $i++) { imagefttext($image, rand(20, 34), rand(-15, 15), $xStart + ($xEnd - $xStart) * $i / $length + rand(-5, 5), rand(40, 60), $fg, Config::getVar('captcha', 'font_location'), String::substr($value, $i, 1)); } // Add some noise to the image. for ($i = 0; $i < 20; $i++) { $color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255)); for ($j = 0; $j < 20; $j++) { imagesetpixel($image, rand(0, $this->getWidth()), rand(0, $this->getHeight()), $color); } } header('Content-type: ' . $this->getMimeType()); imagepng($image); imagedestroy($image); }
function draw_bar_graph($width, $height, $data, $max_value, $filename) { // Create the empty graph image $img = imagecreatetruecolor($width, $height); // Set a white background with black text and gray graphics $bg_color = imagecolorallocate($img, 255, 255, 255); // white $text_color = imagecolorallocate($img, 255, 255, 255); // white $bar_color = imagecolorallocate($img, 0, 0, 0); // black $border_color = imagecolorallocate($img, 192, 192, 192); // light gray // Fill the background imagefilledrectangle($img, 0, 0, $width, $height, $bg_color); // Draw the bars $bar_width = $width / (count($data) * 2 + 1); for ($i = 0; $i < count($data); $i++) { imagefilledrectangle($img, $i * $bar_width * 2 + $bar_width, $height, $i * $bar_width * 2 + $bar_width * 2, $height - $height / $max_value * $data[$i][1], $bar_color); imagestringup($img, 5, $i * $bar_width * 2 + $bar_width, $height - 5, $data[$i][0], $text_color); } // Draw a rectangle around the whole thing imagerectangle($img, 0, 0, $width - 1, $height - 1, $border_color); // Draw the range up the left side of the graph for ($i = 1; $i <= $max_value; $i++) { imagestring($img, 5, 0, $height - $i * ($height / $max_value), $i, $bar_color); } // Write the graph image to a file imagepng($img, $filename, 5); imagedestroy($img); }
public function generate() { $im_width = $this->_owner->getImageWidth(); $im_height = $this->_owner->getImageHeight(); //Resample before detection? $ratio = 0; $diff_width = 320 - $im_width; $diff_height = 240 - $im_height; if ($diff_width > $diff_height) { $ratio = $im_width / 320; } else { $ratio = $im_height / 240; } if ($ratio != 0) { $this->reduced_canvas = imagecreatetruecolor($im_width / $ratio, $im_height / $ratio); imagecopyresampled($this->reduced_canvas, $this->_owner->image, 0, 0, 0, 0, $im_width / $ratio, $im_height / $ratio, $im_width, $im_height); $stats = $this->getImageStats($this->reduced_canvas); $this->face = $this->detectGreedyBigToSmall($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']); if ($this->face['w'] > 0) { $this->face['x'] *= $ratio; $this->face['y'] *= $ratio; $this->face['w'] *= $ratio; } } else { $stats = $this->getImageStats($this->_owner->image); $this->face = $this->detectGreedyBigToSmall($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']); } return $this->face['w'] > 0; }
/** * Factory method that creates a true-color image object * * @param int $width * @param int $height * @return WideImage_TrueColorImage */ static function create($width, $height) { if ($width * $height <= 0 || $width < 0) { throw new WideImage_InvalidImageDimensionException("Can't create an image with dimensions [{$width}, {$height}]."); } return new WideImage_TrueColorImage(imagecreatetruecolor($width, $height)); }
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 output() { $arr = $this->ret; $bg = DATA_DIR . '/cache/vcodebg.png'; $image = imagecreatefrompng($bg); list($w, $baseH) = getimagesize($bg); header('Content-type: image/png'); $x = 1; foreach ($arr as $i => $filename) { list($w, $h) = getimagesize($filename); $source = imagecreatefrompng($filename); $t_id = imagecolortransparent($source); $rotate = imagerotate($source, rand(-20, 20), $t_id); $w2 = $w * $baseH / $h; imagecopyresized($image, $rotate, $x, 0, 0, 0, $w2, $baseH, $w, $h); imagedestroy($source); imagedestroy($rotate); $x += $w2; } $x += 1; $dst = imagecreatetruecolor($x, $baseH); imagecopyresampled($dst, $image, 0, 0, 0, 0, $x, $baseH, $x, $baseH); imagepng($dst); imagedestroy($image); imagedestroy($dst); exit; }
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; }