public function getHashValue($img) { $width = imagesx($img); $height = imagesy($img); $total = 0; $array = array(); for ($y = 0; $y < $height; $y++) { for ($x = 0; $x < $width; $x++) { $gray = imagecolorat($img, $x, $y) >> 8 & 0xff; if (!is_array($array[$y])) { $array[$y] = array(); } $array[$y][$x] = $gray; $total += $gray; } } $average = intval($total / (64 * $this->rate * $this->rate)); $result = ''; for ($y = 0; $y < $height; $y++) { for ($x = 0; $x < $width; $x++) { if ($array[$y][$x] >= $average) { $result .= '1'; } else { $result .= '0'; } } } return $result; }
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 graph_error($string) { global $vars, $config, $debug, $graphfile; $vars['bg'] = 'FFBBBB'; include 'includes/graphs/common.inc.php'; $rrd_options .= ' HRULE:0#555555'; $rrd_options .= " --title='" . $string . "'"; rrdtool_graph($graphfile, $rrd_options); if ($height > '99') { shell_exec($rrd_cmd); d_echo('<pre>' . $rrd_cmd . '</pre>'); if (is_file($graphfile) && !$debug) { header('Content-type: image/png'); $fd = fopen($graphfile, 'r'); fpassthru($fd); fclose($fd); unlink($graphfile); exit; } } else { if (!$debug) { header('Content-type: image/png'); } $im = imagecreate($width, $height); $px = (imagesx($im) - 7.5 * strlen($string)) / 2; imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0)); imagepng($im); imagedestroy($im); exit; } }
public function filter($value) { if (!file_exists($value)) { throw new Zend_Filter_Exception('Image does not exist: ' . $value); } $image = imagecreatefromstring(file_get_contents($value)); if (false === $image) { throw new Zend_Filter_Exception('Can\'t load image: ' . $value); } // find ratio to scale down to // TODO: pass 600 as parameter in the future $origWidth = imagesx($image); $origHeight = imagesy($image); $ratio = max($origWidth, $origHeight) / 600; if ($ratio > 1) { // img too big! create a scaled down image $newWidth = round($origWidth / $ratio); $newHeight = round($origHeight / $ratio); $resized = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight); // determine type and store to disk $explodeResult = explode(".", $value); $type = strtolower($explodeResult[count($explodeResult) - 1]); $writeFunc = 'image' . $type; if ($type == 'jpeg' || $type == 'jpg') { imagejpeg($resized, $value, 100); } else { $writeFunc($resized, $value); } } return $value; }
/** * method puts image onto map image * * @param Map $map * @param resources $imageToPut */ public function putImage(Map $map, $imageToPut) { $mapImage = $map->getImage(); $width = imagesx($imageToPut); $height = imagesy($imageToPut); imagecopy($mapImage, $imageToPut, imagesx($mapImage) - $width, 0, 0, 0, $width, $height); }
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; }
/** * 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); }
public function apply($resource) { // Extract arguments @(list(, $direction, $step, $thickness, $color) = func_get_args()); $step = (int) $step; $thickness = (int) $thickness; if ($step < 2) { $step = 2; } // Get resolution $width = imagesx($resource); $height = imagesy($resource); if ($width === false || $height === false) { throw new Exception("An error was encountered while getting image resolution"); } // Apply effect switch ($direction) { case self::VERTICAL: $x = 0; while (($x += $step) < $width) { parent::apply($resource, $x, 0, $x, $height, $thickness, $color); } break; case self::HORIZONTAL: default: $y = 0; while (($y += $step) < $height) { parent::apply($resource, 0, $y, $width, $y, $thickness, $color); } } return $resource; }
/** * 压缩图像尺寸 * @param $pic 源图像 * @param $dst_pic 目标图像 * @param $width 宽度 * @param $height 高度 * @param $qulitity 质量 * @return unknown_type */ static function thumbnail($pic, $dst_pic, $max_width, $max_height = null, $qulitity = 100, $copy = true) { $im = self::readfile($pic); $old_w = imagesx($im); $old_h = imagesy($im); if ($max_height == null) { $max_height = $max_width; } if ($old_w > $max_width or $old_h > $max_height) { $w_h = $old_w / $old_h; $h_w = $old_h / $old_w; if ($w_h > $h_w) { $width = $max_width; $height = $width * $h_w; } else { $height = $max_height; $width = $height * $w_h; } $newim = imagecreatetruecolor($width, $height); imagecopyresampled($newim, $im, 0, 0, 0, 0, $width, $height, $old_w, $old_h); imagejpeg($newim, $dst_pic, $qulitity); imagedestroy($im); } elseif ($pic != $dst_pic and $copy) { copy($pic, $dst_pic); } }
/** * {@inheritdoc} */ public function apply(&$image) { $inputWidth = imagesx($image); $inputHeight = imagesy($image); $width = $inputWidth; $height = $inputHeight; // bigger if ($height < $this->outputHeight) { $width = $this->outputHeight / $height * $width; $height = $this->outputHeight; } if ($width < $this->outputWidth) { $height = $this->outputWidth / $width * $height; $width = $this->outputWidth; } // taller if ($height > $this->outputHeight) { $width = $this->outputHeight / $height * $width; $height = $this->outputHeight; } // wider if ($width > $this->outputWidth) { $height = $this->outputWidth / $width * $height; $width = $this->outputWidth; } $output = imagecreatetruecolor($width, $height); imagecopyresampled($output, $image, 0, 0, 0, 0, $width, $height, $inputWidth, $inputHeight); $image = $output; }
function resize_image($pathToImages, $pathToThumbs, $thumbWidth) { // open the directory $dir = opendir($pathToImages); // loop through it, looking for any/all JPG files: while (false !== ($fname = readdir($dir))) { // parse path for the extension $info = pathinfo($pathToImages . $fname); // continue only if this is a JPEG image if (strtolower($info['extension']) == 'jpg' && $fname != "thumb.jpg") { // load image and get image size $img = imagecreatefromjpeg("{$pathToImages}" . "/" . "{$fname}"); $width = imagesx($img); $height = imagesy($img); // calculate thumbnail size $new_width = $thumbWidth; $new_height = floor($height * ($thumbWidth / $width)); // create a new temporary image $tmp_img = imagecreatetruecolor($new_width, $new_height); // copy and resize old image into new image imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // save thumbnail into a file imagejpeg($tmp_img, "{$pathToThumbs}" . "/" . "{$fname}"); echo "Se redujo la imagen {$fname} <br />"; //echo "$pathToThumbs" . "/" . "$fname<br/>"; } } // close the directory closedir($dir); }
public static function ImageHue(&$image, $hue, $saturation) { $width = imagesx($image); $height = imagesy($image); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $rgb = imagecolorat($image, $x, $y); $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; $alpha = ($rgb & 0x7f000000) >> 24; $hsl = ColorUtils::rgb2hsl(array('r' => $r, 'g' => $g, 'b' => $b)); $h = $hsl['h'] / 360; $s = $hsl['s'] / 100; $h += $hue / 360; $s += $saturation / 100; if ($h > 1) { $h--; } if ($s > 1) { $s--; } $hsl['h'] = $h * 360; $hsl['s'] = $s * 100; $rgb = ColorUtils::hsl2rgb($hsl); imagesetpixel($image, $x, $y, imagecolorallocatealpha($image, $rgb['r'], $rgb['g'], $rgb['b'], $alpha)); } } }
/** * Generate a cached thumbnail for object lists (eg. carrier, order states...etc) * * @param string $image Real image filename * @param string $cacheImage Cached filename * @param integer $size Desired size */ function cacheImage($image, $cacheImage, $size, $imageType = 'jpg') { if (file_exists($image)) { if (!file_exists(_PS_TMP_IMG_DIR_ . $cacheImage)) { $imageGd = $imageType == 'gif' ? imagecreatefromgif($image) : imagecreatefromjpeg($image); $x = imagesx($imageGd); $y = imagesy($imageGd); /* Size is already ok */ if ($y < $size) { copy($image, _PS_TMP_IMG_DIR_ . $cacheImage); } else { $ratioX = $x / ($y / $size); $newImage = $imageType == 'gif' ? imagecreate($ratioX, $size) : imagecreatetruecolor($ratioX, $size); /* Allow to keep nice look even if resized */ $white = imagecolorallocate($newImage, 255, 255, 255); imagefill($newImage, 0, 0, $white); imagecopyresampled($newImage, $imageGd, 0, 0, 0, 0, $ratioX, $size, $x, $y); imagecolortransparent($newImage, $white); /* Quality alteration and image creation */ if ($imageType == 'gif') { imagegif($newImage, _PS_TMP_IMG_DIR_ . $cacheImage); } else { imagejpeg($newImage, _PS_TMP_IMG_DIR_ . $cacheImage, 86); } } } return '<img src="../img/tmp/' . $cacheImage . '" alt="" class="imgm" />'; } return ''; }
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; } }
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); } }
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; }
/** * * @param string $playername Minecraft player name * @param resource $avatar the rendered avatar (for example player head) * * @param string $background Image Path or Standard Value * @return resource the generated banner */ public static function player($playername, $avatar = NULL, $background = NULL) { $canvas = MinecraftBanner::getBackgroundCanvas(self::PLAYER_WIDTH, self::PLAYER_HEIGHT, $background); $head_height = self::AVATAR_SIZE; $head_width = self::AVATAR_SIZE; $avater_x = self::PLAYER_PADDING; $avater_y = self::PLAYER_HEIGHT / 2 - self::AVATAR_SIZE / 2; if ($avatar == NULL) { $avatar = imagecreatefrompng(__DIR__ . "/img/head.png"); imagesavealpha($avatar, true); imagecopy($canvas, $avatar, $avater_x, $avater_y, 0, 0, $head_width, $head_height); } else { $head_width = imagesx($avatar); $head_height = imagesy($avatar); if ($head_width > self::AVATAR_SIZE) { $head_width = self::AVATAR_SIZE; } if ($head_height > self::AVATAR_SIZE) { $head_height = self::AVATAR_SIZE; } $center_x = $avater_x + self::AVATAR_SIZE / 2 - $head_width / 2; $center_y = $avater_y + self::AVATAR_SIZE / 2 - $head_height / 2; imagecopy($canvas, $avatar, $center_x, $center_y, 0, 0, $head_width, $head_height); } $box = imagettfbbox(self::TEXT_SIZE, 0, MinecraftBanner::FONT_FILE, $playername); $text_width = abs($box[4] - $box[0]); $text_color = imagecolorallocate($canvas, 255, 255, 255); $remaining = self::PLAYER_WIDTH - self::AVATAR_SIZE - $avater_x - self::PLAYER_PADDING; $text_posX = $avater_x + self::AVATAR_SIZE + $remaining / 2 - $text_width / 2; $text_posY = $avater_y + self::AVATAR_SIZE / 2 + self::TEXT_SIZE / 2; imagettftext($canvas, self::TEXT_SIZE, 0, $text_posX, $text_posY, $text_color, MinecraftBanner::FONT_FILE, $playername); return $canvas; }
protected function getImageStats($canvas) { $image_width = imagesx($canvas); $image_height = imagesy($canvas); $iis = $this->computeII($canvas, $image_width, $image_height); return array('width' => $image_width, 'height' => $image_height, 'ii' => $iis['ii'], 'ii2' => $iis['ii2']); }
function set($a_image) { $this->clear(); $this->m_handle = $a_image; $this->m_width = imagesx($this->m_handle); $this->m_height = imagesy($this->m_handle); }
/** 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; }
function thumbnail($imgfile) { //detect image format //$this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile); $this->img["format"] = preg_replace('/.*\\.(.*)$/', "\\1", $imgfile); $this->img["format"] = strtoupper($this->img["format"]); if ($this->img["format"] == "JPG" || $this->img["format"] == "JPEG") { //JPEG $this->img["format"] = "JPEG"; $this->img["src"] = ImageCreateFromJPEG($imgfile); } elseif ($this->img["format"] == "PNG") { //PNG $this->img["format"] = "PNG"; $this->img["src"] = ImageCreateFromPNG($imgfile); } elseif ($this->img["format"] == "GIF") { //GIF $this->img["format"] = "GIF"; $this->img["src"] = ImageCreateFromGIF($imgfile); } elseif ($this->img["format"] == "WBMP") { //WBMP $this->img["format"] = "WBMP"; $this->img["src"] = ImageCreateFromWBMP($imgfile); } else { //DEFAULT echo "Not Supported File"; exit; } @($this->img["lebar"] = imagesx($this->img["src"])); @($this->img["tinggi"] = imagesy($this->img["src"])); //default quality jpeg $this->img["quality"] = 75; }
/** * Method to apply a filter to an image resource. * * @param array $options An array of options for the filter. * * @return void * * @throws InvalidArgumentException * @throws RuntimeException */ public function execute(array $options = array()) { // Verify that image filter support for PHP is available. if (!function_exists('imagefilter')) { throw new RuntimeException('The imagefilter function for PHP is not available.'); } if (empty($options)) { throw new InvalidArgumentException('No valid amount was given. Expected float.'); } $value = (int) array_shift($options); if ($value == 0) { $value = 128; } $width = imagesx($this->handle); $height = imagesy($this->handle); for ($x = 0; $x < $width; ++$x) { for ($y = 0; $y < $height; ++$y) { $index = imagecolorat($this->handle, $x, $y); $rgb = imagecolorsforindex($this->handle, $index); $r = $rgb['red']; $g = $rgb['green']; $b = $rgb['blue']; $a = $rgb['alpha']; $v = round(($r + $g + $b) / 3) >= $value ? 255 : 0; $color = imagecolorallocatealpha($this->handle, $v, $v, $v, $a); if ($color === false) { $color = imagecolorclosestalpha($this->handle, $v, $v, $v, $a); } imagesetpixel($this->handle, $x, $y, $color); } } }
/** * 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; }
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 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; }
public function apply($resource) { // Get arguments @(list(, $thickness, $color, $sides) = func_get_args()); $thickness = (int) $thickness; if (!$color) { $color = '#000000'; } $sides = (int) $sides; // Get resolution $width = imagesx($resource); $height = imagesy($resource); if ($width === false || $height === false) { throw new Exception("An error was encountered while getting image resolution"); } // Define adjustment $z = $thickness / 2; // Draw borders if ($sides == self::ALL || $sides == self::TOP) { parent::apply($resource, 0, $z, $width, $z, $thickness, $color); } if ($sides == self::ALL || $sides == self::RIGHT) { parent::apply($resource, $width - $z, $z, $width - $z, $height, $thickness, $color); } if ($sides == self::ALL || $sides == self::BOTTOM) { parent::apply($resource, $width - $z, $height - $z, 0, $height - $z, $thickness, $color); } if ($sides == self::ALL || $sides == self::LEFT) { parent::apply($resource, $z, $height, $z, 0, $thickness, $color); } return $resource; }
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; }
public function store_codeOp() { if ($_GET['text']) { $text = $_GET['text']; $size = '6'; $level = 'H'; $logo = BASE_RESOURCE_PATH . DS . '/logo_2.png'; $padding = '2'; $path = BASE_RESOURCE_PATH . DS . 'phpqrcode'; $QR = $path . 'qrcode.png'; require_once BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'phpqrcode.php'; QRcode::png($text, $QR, $level, $size, $padding); if ($logo !== false) { $QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR); $QR_height = imagesy($QR); $logo_width = imagesx($logo); $logo_height = imagesy($logo); $logo_qr_width = $QR_width / 5; $scale = $logo_width / $logo_qr_width; $logo_qr_height = $logo_height / $scale; $from_width = ($QR_width - $logo_qr_width) / 2; imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height); } header("Content-Type:image/jpg"); imagepng($QR); } else { output_error('参数错误00023'); } }
/** * Contructor method. Will create a new image from the target file. * Accepts an image filename as a string. Method also works out how * big the image is and stores this in the $image array. * * @param string $imgFile The image filename. */ public function ImageManipulation($imgfile) { //detect image format $this->image["format"] = preg_replace("/.*\\.(.*)\$/", "\\1", $imgfile); //$this->image["format"] = preg_replace(".*\.(.*)$", "\\1", $imgfile); $this->image["format"] = strtoupper($this->image["format"]); // convert image into usable format. if ($this->image["format"] == "JPG" || $this->image["format"] == "JPEG") { //JPEG $this->image["format"] = "JPEG"; $this->image["src"] = ImageCreateFromJPEG($imgfile); } elseif ($this->image["format"] == "PNG") { //PNG $this->image["format"] = "PNG"; $this->image["src"] = imagecreatefrompng($imgfile); } elseif ($this->image["format"] == "GIF") { //GIF $this->image["format"] = "GIF"; $this->image["src"] = ImageCreateFromGif($imgfile); } elseif ($this->image["format"] == "WBMP") { //WBMP $this->image["format"] = "WBMP"; $this->image["src"] = ImageCreateFromWBMP($imgfile); } else { //DEFAULT return false; } // Image is ok $this->imageok = true; // Work out image size $this->image["sizex"] = imagesx($this->image["src"]); $this->image["sizey"] = imagesy($this->image["src"]); }
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; }