本文整理汇总了PHP中imagesX函数的典型用法代码示例。如果您正苦于以下问题:PHP imagesX函数的具体用法?PHP imagesX怎么用?PHP imagesX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagesX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Method to apply a background color to an image resource.
*
* @param array $options An array of options for the filter.
* color Background matte color
*
* @return void
*
* @since 3.4
* @throws InvalidArgumentException
* @deprecated 5.0 Use Joomla\Image\Filter\Backgroundfill::execute() instead
*/
public function execute(array $options = array())
{
// Validate that the color value exists and is an integer.
if (!isset($options['color'])) {
throw new InvalidArgumentException('No color value was given. Expected string or array.');
}
$colorCode = !empty($options['color']) ? $options['color'] : null;
// Get resource dimensions
$width = imagesX($this->handle);
$height = imagesY($this->handle);
// Sanitize color
$rgba = $this->sanitizeColor($colorCode);
// Enforce alpha on source image
if (imageIsTrueColor($this->handle)) {
imageAlphaBlending($this->handle, false);
imageSaveAlpha($this->handle, true);
}
// Create background
$bg = imageCreateTruecolor($width, $height);
imageSaveAlpha($bg, empty($rgba['alpha']));
// Allocate background color.
$color = imageColorAllocateAlpha($bg, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
// Fill background
imageFill($bg, 0, 0, $color);
// Apply image over background
imageCopy($bg, $this->handle, 0, 0, 0, 0, $width, $height);
// Move flattened result onto curent handle.
// If handle was palette-based, it'll stay like that.
imageCopy($this->handle, $bg, 0, 0, 0, 0, $width, $height);
// Free up memory
imageDestroy($bg);
return;
}
示例2: createthumb
function createthumb($name, $filename, $new_w, $new_h)
{
// $src_img=null;
//$system=explode(".",$name);
if (preg_match("/jpg|jpeg|JPG/", $name)) {
$src_img = imagecreatefromjpeg($name);
}
if (preg_match("/png/", $name)) {
$src_img = imagecreatefrompng($name);
}
if (preg_match("/gif/", $name)) {
$src_img = imagecreatefromgif($name);
}
$old_x = imagesX($src_img);
$old_y = imagesY($src_img);
$thumb_w = (int) $new_w;
$thumb_h = (int) $new_h;
//$dst_img=imagecreate($thumb_w,$thumb_h);
$dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
//imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
if (preg_match("/png|PNG/", $name)) {
imagepng($dst_img, $filename);
} else {
imagejpeg($dst_img, $filename, 100);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
示例3: getWidth
/**
* Get the width of this Image instance
* @return int width
*/
public function getWidth()
{
if (!isset($this->width)) {
$this->width = imagesX($this->resource);
}
return $this->width;
}
示例4: generate_thumbnail
function generate_thumbnail($file, $mime)
{
global $config;
gd_capabilities();
list($file_type, $exact_type) = explode("/", $mime);
if (_JB_GD_INSTALLED && ($file_type = "image")) {
if ($exact_type != "gif" && $exact_type != "png" && $exact_type != "jpeg") {
return false;
}
if ($exact_type == "gif" && !_JB_GD_GIF) {
return false;
}
if ($exact_type == "png" && !_JB_GD_PNG) {
return false;
}
if ($exact_type == "jpeg" && !_JB_GD_JPG) {
return false;
}
// Load up the original and get size
// NOTE: use imageCreateFromString to avoid to have to check what type of image it is
$original = imageCreateFromString(file_get_contents($file));
$original_w = imagesX($original);
$original_h = imagesY($original);
// Only if the image is really too big, resize it
// NOTE: if image is smaller than target size, don't do anything.
// We *could* copy the original to filename_thumb, but since it's the same
// it would be a waste of precious resources
if ($original_w > $config['uploader']['thumb_w'] || $original_h > $config['uploader']['thumb_h']) {
// If original is wider than it's high, resize the width and vice versa
// NOTE: '>=' cause otherwise it's possible that $scale isn't computed
if ($original_w >= $original_h) {
$scaled_w = $config['uploader']['thumb_w'];
// Figure out how much smaller that target is than original
// and apply it to height
$scale = $config['uploader']['thumb_w'] / $original_w;
$scaled_h = ceil($original_h * $scale);
} elseif ($original_w <= $original_h) {
$scaled_h = $config['uploader']['thumb_h'];
$scale = $config['uploader']['thumb_h'] / $original_h;
$scaled_w = ceil($original_w * $scale);
}
} else {
// Break out of if($file_type = image) since no resize is possible
return false;
}
// Scale the image
$scaled = imageCreateTrueColor($scaled_w, $scaled_h);
imageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h);
// Store thumbs in jpeg, hope no one minds the 100% quality lol
imageJpeg($scaled, $file . "_thumb", 100);
// Let's be nice to our server
imagedestroy($scaled);
imagedestroy($original);
return true;
}
}
示例5: drawField
function drawField($team)
{
$field = imagecreatefromjpeg("img/field.jpg");
foreach ($team->players as $player) {
$img = drawPlayer($player->number, $player->name);
$width = imagesx($img);
$height = imagesy($img);
$posX = $player->x - ($width - 26) / 2;
$posY = $player->y - 10;
imageAlphaBlending($field, true);
// копировать сюда будем вместе с настройками
imageSaveAlpha($field, true);
// сохраняем
imageCopy($field, $img, $posX, $posY, 0, 0, $width, $height);
//копируем картинку с формой в пустой бокс
}
$copyright = drawCaption("http://www.ezheloko.ru/tactic", 12, 0);
imagecopymerge_alpha($field, $copyright, 240, imagesY($field) - 25, 0, 0, imagesX($copyright), imagesY($copyright), 30);
$name = generateName();
$name = "formations/" . $name . ".png";
imagePng($field, $name);
return $name;
}
示例6: resizeImage
public function resizeImage($dir, $toResize, $maxW = 750, $maxH = 540, $force = false)
{
$imagemToResize = $dir . $toResize;
$ext = "." . end(explode(".", $toResize));
$error = '';
if (!$maxH && !$maxW) {
return true;
}
$largura_alvo = $maxW;
$altura_alvo = $maxH;
if ($maxW <= $largura_alvo && $maxH <= $altura_alvo && ($force = false)) {
return true;
}
$file_dimensions = getimagesize($dir . $toResize);
$fileType = strtolower($file_dimensions['mime']);
if ($fileType == 'image/jpeg' || $fileType == 'image/jpg' || $fileType == 'image/pjpeg') {
$img = imagecreatefromjpeg($imagemToResize);
} else {
if ($fileType == 'image/png') {
$img = imagecreatefrompng($imagemToResize);
} else {
if ($fileType == 'image/gif') {
$img = imagecreatefromgif($imagemToResize);
}
}
}
$largura_original = imagesX($img);
$altura_original = imagesY($img);
$altura_nova = $altura_original * $largura_alvo / $largura_original;
if ($altura_nova > $altura_alvo) {
$altura_nova = $altura_alvo;
$largura_nova = round($largura_original * $altura_alvo / $altura_original);
$nova = ImageCreateTrueColor($largura_nova, $altura_alvo);
if ($fileType == 'image/png' || $fileType == 'image/gif') {
imagealphablending($nova, false);
imagesavealpha($nova, true);
$transparent = imagecolorallocatealpha($nova, 255, 255, 255, 127);
imagefilledrectangle($nova, 0, 0, $largura_nova, $altura_nova, $transparent);
}
imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura_nova, $altura_nova, $largura_original, $altura_original);
} else {
$largura_nova = $largura_alvo;
$nova = ImageCreateTrueColor($largura_alvo, $altura_nova);
if ($fileType == 'image/png' || $fileType == 'image/gif') {
imagealphablending($nova, false);
imagesavealpha($nova, true);
$transparent = imagecolorallocatealpha($nova, 255, 255, 255, 127);
imagefilledrectangle($nova, 0, 0, $largura_alvo, $altura_nova, $transparent);
}
imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura_alvo, $altura_nova, $largura_original, $altura_original);
}
if ($force) {
$nova = ImageCreateTrueColor($maxW, $maxH);
imagecopyresampled($nova, $img, 0, 0, 0, 0, $maxW, $maxH, $largura_original, $altura_original);
}
if ($fileType == 'image/jpeg' || $fileType == 'image/jpg' || $fileType == 'image/pjpeg') {
if (!imagejpeg($nova, $imagemToResize, 100)) {
$error = true;
}
} else {
if ($fileType == 'image/png') {
if (!imagepng($nova, $imagemToResize, 0)) {
$error = true;
}
} else {
if ($fileType == 'image/gif') {
if (!imagegif($nova, $imagemToResize)) {
$error = true;
}
}
}
}
if ($error) {
return 'Erro ao redimencionar ' . $toResize;
} else {
return true;
}
}
示例7: resizeImage
function resizeImage(&$image, $width, $height, $scale = false)
{
$tmp_image = $image;
$original_w = imagesX($image);
$original_h = imagesY($image);
$tmp_w = $tmp_h = 0;
if ($scale === true) {
$tmp_w = $width;
$tmp_h = $width / $original_w * $original_h;
if ($width / $original_w * $original_h > $height) {
$tmp_h = $height;
$tmp_w = $height / $original_h * $original_w;
}
$width = $tmp_w;
$height = $tmp_h;
}
$image = imageCreateTrueColor($width, $height);
imageCopyResized($image, $tmp_image, 0, 0, 0, 0, $width, $height, $original_w, $original_h);
imageDestroy($tmp_image);
}
示例8: explode
$terminalY = 24;
}
if (isset($argv[2])) {
$imagemnome = $argv[2];
} else {
$imagemnome = "apple.jpg";
}
$formato = explode('.', $imagemnome);
$formato = $formato[count($formato) - 1];
if ($formato == 'jpg' or $formato == 'jpeg') {
$imagem = imagecreatefromjpeg($imagemnome);
} elseif ($formato == 'png') {
$imagem = imagecreatefrompng($imagemnome);
}
$nova = imagecreatetruecolor($terminalX, $terminalY);
$tamanhoX = imagesX($imagem);
$tamanhoY = imagesY($imagem);
imagecopyresampled($nova, $imagem, 0, 0, 0, 0, $terminalX, $terminalY, $tamanhoX, $tamanhoY);
for ($y = 0; $y <= $terminalY; $y++) {
if ($argv[3] == '-s') {
usleep(100000);
}
for ($x = 0; $x <= $terminalX; $x++) {
$rgb = imagecolorat($nova, $x, $y);
$rgb = imagecolorsforindex($nova, $rgb);
$r = $rgb['red'] * 1.0;
$g = $rgb['green'] * 1.0;
$b = $rgb['blue'] * 1.0;
if ($r + $g + $b < 100) {
//Preto
echo "[30mA" . "[0m";
示例9: addtagborder2
function addtagborder2($oim, $x, $y, $i, $startx, $starty, $outputsize, $shiftx, $shifty, $fuzzy)
{
$width = imagesX($oim);
$height = imagesY($oim);
if ($fuzzy < 54 * 2) {
$addx = 54 * 2 + 4;
} else {
$addx = 0;
}
if ($fuzzy < 22 * 2) {
$addy = 22 * 2 + 4;
} else {
$addy = 0;
}
error_log(sprintf("addtagborder2: original: %d x %d => new size: %d x %d\n", $width, $height, $width + $addx, $height + $addy));
$im = imagecreate($width + $addx, $height + $addy);
$white = imageColorAllocate($im, 0xff, 0xff, 0xff);
imageCopyMerge($im, $oim, 55, 23, 0, 0, imagesX($oim), imagesY($oim), 100);
// 不需要算序號
$tagx = $startx;
$tagy = $starty;
if ($i < $x) {
// add top
$topim = tagXline($tagx, $outputsize['x']);
imageCopyMerge($im, $topim, 0, 0, 0, 0, imagesX($topim), imagesY($topim), 100);
imagedestroy($topim);
}
if ($i >= $x * ($y - 1)) {
// add buttom
$topim = tagXline($tagx, $outputsize['x']);
$ozy = $outputsize['y'];
$tty = 22 + ($shifty % $ozy == 0 ? $ozy : $shifty % $ozy) * 315 + 2;
// echo "tty = $tty $tileY % $ozy \n";
imageCopyMerge($im, $topim, 0, $tty, 0, 0, imagesX($topim), imagesY($topim), 100);
imagedestroy($topim);
}
if ($i % $x == 0) {
// add left
$topim = tagYline($tagy, $outputsize['y']);
imageCopyMerge($im, $topim, 0, 0, 0, 0, imagesX($topim), imagesY($topim), 100);
imagedestroy($topim);
}
if (($i + 1) % $x == 0) {
// add right
$topim = tagYline($tagy, $outputsize['y']);
$ozx = $outputsize['x'];
$ttx = 54 + ($shiftx % $ozx == 0 ? $ozx : $shiftx % $ozx) * 315 + 2;
// echo "ttx = $ttx $tileX % $ozx \n";
imageCopyMerge($im, $topim, $ttx, 0, 0, 0, imagesX($topim), imagesY($topim), 100);
imagedestroy($topim);
}
return $im;
}
示例10: crearImagen
function crearImagen($origen, $destino, $ancho = null, $alto = null, $background = false, $extension = ".jpg", $logo = "")
{
$colors = array(255, 255, 255);
list($w, $h, $type) = getimagesize($origen);
if ($ancho == null) {
$ancho = $w;
}
if ($alto == null) {
$alto = $h;
}
if ($type == 1) {
$src_img = @imagecreatefromgif($origen);
} else {
if ($type == 3) {
$src_img = @imagecreatefrompng($origen);
} else {
if ($type == 6) {
$src_img = @imagecreatefromwbmp($origen);
}
}
}
if (!empty($src_img)) {
@imagegif($src_img, $origen);
}
ini_set('gd.jpeg_ignore_warning', 1);
$old_x = imageSX($src_img);
$old_y = imageSY($src_img);
$thumb_w = $ancho;
$thumb_h = $alto;
$wRatio = $thumb_w / $old_x;
$hRatio = $thumb_h / $old_y;
if ($thumb_w > $old_x && $thumb_h > $old_y) {
$ancho = $old_x;
$altura = $old_y;
} else {
if ($wRatio * $old_y < $thumb_h) {
$altura = ceil($wRatio * $old_y);
$ancho = $thumb_w;
} else {
if ($hRatio * $old_x < $thumb_w) {
$ancho = ceil($hRatio * $old_x);
$altura = $thumb_h;
} else {
$ancho = $thumb_w;
$altura = $thumb_h;
}
}
}
if (!$background) {
$thumb_w = $ancho;
$thumb_h = $altura;
} else {
$colors = hex2rgb($background);
}
$posx = $thumb_w / 2 - $ancho / 2;
$posy = $thumb_h / 2 - $altura / 2;
$dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
$colorfondo = imagecolorallocate($dst_img, $colors[0], $colors[1], $colors[2]);
imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $colorfondo);
imagecopyresampled($dst_img, $src_img, $posx, $posy, 0, 0, $ancho, $altura, $old_x, $old_y);
if ($logo != '') {
$img_logo = imagecreatefrompng($logo);
$logo_w = imagesX($img_logo);
$logo_h = imagesY($img_logo);
$pos_x = $ancho - $logo_w;
imagecopyresampled($dst_img, $img_logo, $pos_x, 0, 0, 0, $pos_x, 0, $ancho, $altura);
// imagecopy($dst_img, $img_logo, $ancho-$logo_w, $alto-$logo_h, 0, 0, $logo_w, $logo_h);
imagecopy($dst_img, $img_logo, $pos_x, 0, 0, 0, $ancho, $logo_h);
}
switch ($extension) {
case '.gif':
imagegif($dst_img, $destino);
break;
case '.jpg':
default:
imagejpeg($dst_img, $destino, 90);
break;
}
imagedestroy($dst_img);
imagedestroy($src_img);
$oldumask = umask(0);
chmod($destino, 0777);
umask($oldumask);
}
示例11: wytnij
static function wytnij($zrodlowy, $docelowy, $newX, $newY)
{
if (!file_exists($zrodlowy)) {
Strona::blad('Brak pliku: ' . $zrodlowy);
return 1;
}
$return = 0;
if ($img = @imagecreatefromjpeg($zrodlowy)) {
$oldX = imagesX($img);
$oldY = imagesY($img);
if ($newX == 0) {
$newX = $oldX;
}
if ($newY == 0) {
$newY = $oldY;
}
$im = @imagecreatetruecolor($newX, $newY);
if (!@imagecopy($im, $img, 0, 0, 0, 0, $newX, $newY)) {
Strona::blad('Błąd imagecopyresized() ' . $zrodlowy);
} else {
@imagejpeg($im, $docelowy, 120);
$return = 0;
}
} else {
Strona::blad('Błąd imagecreatefromjpeg() ' . $zrodlowy);
}
return $return;
}
示例12: getWidth
/**
* get image width
*/
public function getWidth()
{
return imagesX($this->gd);
}
示例13: rotate
/**
* image::rotate()
*
* @param mixed $direction
* @return
*/
function rotate($direction)
{
if (empty($this->error)) {
if ($this->is_destroy) {
$this->get_createImage();
}
$direction = intval($direction);
$direction = 360 - $direction % 360;
if ($direction != 0 and $direction != 360) {
$this->set_memory_limit();
$workingImage = imagerotate($this->createImage, $direction, -1);
imagealphablending($workingImage, true);
imagesavealpha($workingImage, true);
$this->createImage = $workingImage;
$this->create_Image_info['width'] = imagesX($this->createImage);
$this->create_Image_info['height'] = imagesY($this->createImage);
}
}
}
示例14: hashImage
public static function hashImage($src)
{
if (!$src) {
return false;
}
/*缩小圖片尺寸*/
$delta = 8 * self::$rate;
$img = imageCreateTrueColor($delta, $delta);
imageCopyResized($img, $src, 0, 0, 0, 0, $delta, $delta, imagesX($src), imagesY($src));
/*計算圖片灰階值*/
$grayArray = array();
for ($y = 0; $y < $delta; $y++) {
for ($x = 0; $x < $delta; $x++) {
$rgb = imagecolorat($img, $x, $y);
$col = imagecolorsforindex($img, $rgb);
$gray = intval(($col['red'] + $col['green'] + $col['blue']) / 3) & 0xff;
$grayArray[] = $gray;
}
}
imagedestroy($img);
/*計算所有像素的灰階平均值*/
$average = array_sum($grayArray) / count($grayArray);
/*計算 hash 值*/
$hashStr = '';
foreach ($grayArray as $gray) {
$hashStr .= $gray >= $average ? '1' : '0';
}
return $hashStr;
}
示例15: create_thumbnail_watermark
function create_thumbnail_watermark($source, $destination, $new_width = 100, $new_height = 'auto', $quality = 100, $font_path, $font_size, $text_show)
{
$im_src = imagecreatefromjpeg($source);
if (!$im_src) {
return;
}
$im_width = imagesX($im_src);
$im_height = imagesY($im_src);
if (!is_int($new_width) && is_int($new_height)) {
// resize the image based on height
$ratio = $im_height / $new_height;
$new_width = floor($im_width / $ratio);
} elseif (is_int($new_width) && !is_int($new_height)) {
// resize the image based on the width
$ratio = $im_width / $new_width;
$new_height = floor($im_height / $ratio);
}
// create blank image
$im = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($im, $im_src, 0, 0, 0, 0, $new_width, $new_height, $im_width, $im_height);
/****************************/
$blue = imagecolorallocate($im, 253, 186, 16);
// tentukan warna teks dalam RGB (255,255,255)
$shadow = imagecolorallocate($im, 178, 178, 178);
// efek teks shadow
// imagettftext($im, $font_size, 0, 31, 191, $shadow, $font_path, $text_show); // posisikan logo watermark pada gambar
imagettftext($im, $font_size, 0, 30, 190, $blue, $font_path, $text_show);
/*********************************/
imagejpeg($im, $destination, $quality);
imagedestroy($im);
imagedestroy($im_src);
}