本文整理汇总了PHP中imageflip函数的典型用法代码示例。如果您正苦于以下问题:PHP imageflip函数的具体用法?PHP imageflip怎么用?PHP imageflip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageflip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: orientate
/**
* Orientate the image.
*
* @param UploadedFile $file
* @param $orientation
* @return UploadedFile
*/
protected function orientate(UploadedFile $file, $orientation)
{
$image = imagecreatefromjpeg($file->getRealPath());
switch ($orientation) {
case 2:
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 3:
$image = imagerotate($image, 180, 0);
break;
case 4:
$image = imagerotate($image, 180, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 5:
$image = imagerotate($image, -90, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 6:
$image = imagerotate($image, -90, 0);
break;
case 7:
$image = imagerotate($image, 90, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 8:
$image = imagerotate($image, 90, 0);
break;
}
imagejpeg($image, $file->getRealPath(), 90);
return new UploadedFile($file->getRealPath(), $file->getClientOriginalName(), $file->getMimeType(), $file->getSize());
}
示例2: imagerotate
/**
* Substitute for GD imagerotate
*
* @param image $imgSrc
* @param int $angle
* @param int $bgd_colour
* @return image
*/
function imagerotate($imgSrc, $angle, $bgd_colour)
{
// ensuring we got really RightAngle (if not we choose the closest one)
$angle = min((int) (($angle + 45) / 90) * 90, 270);
// no need to fight
if ($angle == 0) {
return $imgSrc;
}
// dimenstion of source image
$srcX = imagesx($imgSrc);
$srcY = imagesy($imgSrc);
switch ($angle) {
case 90:
$imgDest = imagecreatetruecolor($srcY, $srcX);
for ($x = 0; $x < $srcX; $x++) {
for ($y = 0; $y < $srcY; $y++) {
imagecopy($imgDest, $imgSrc, $srcY - $y - 1, $x, $x, $y, 1, 1);
}
}
break;
case 180:
$imgDest = imageflip($imgSrc, IMAGE_FLIP_BOTH);
break;
case 270:
$imgDest = imagecreatetruecolor($srcY, $srcX);
for ($x = 0; $x < $srcX; $x++) {
for ($y = 0; $y < $srcY; $y++) {
imagecopy($imgDest, $imgSrc, $y, $srcX - $x - 1, $x, $y, 1, 1);
}
}
break;
}
return $imgDest;
}
示例3: Mirror
public static function Mirror($image, $outtype = "png", $raw = false, $vertical = false)
{
if (!$raw) {
list($size["x"], $size["y"]) = getimagesize($image);
} else {
list($size["x"], $size["y"]) = getimagesizefromstring($image);
}
$data = RandImg::loadImage($image, $raw);
imageflip($data, $vertical ? IMG_FLIP_VERTICAL : IMG_FLIP_HORIZONTAL);
return RandImg::makeImageString($data, $outtype);
}
示例4: applyRotation
protected function applyRotation($image, $rotation)
{
if ($rotation & self::PATTERN_FLIP_H) {
imageflip($image, IMG_FLIP_HORIZONTAL);
}
if ($rotation & self::PATTERN_FLIP_V) {
imageflip($image, IMG_FLIP_VERTICAL);
}
if ($rotation & self::PATTERN_ANGLE_MASK) {
$image = imagerotate($image, ($rotation & self::PATTERN_ANGLE_MASK) * 90, $this->bgColorValue);
}
return $image;
}
示例5: renderBody
public function renderBody($skin, $size, $hat = false)
{
$bodyWidth = (int) floor($size / 2);
$bodyHeight = (int) floor($bodyWidth * 1.5);
$armWidth = (int) floor($size / 4);
$width = (int) $bodyWidth * 2;
$height = (int) $width * 2;
$skin = base64_decode($skin);
$imgBody = imagecreatetruecolor($width, $height);
$imgSkin = imagecreatefromstring($skin);
$transparency = imagecolorat($imgSkin, 0, 0);
$alphaRed = $transparency >> 16 & 0xff;
$alphaGreen = $transparency >> 8 & 0xff;
$alphaBlue = $transparency & 0xff;
// Make body transparent
imagesavealpha($imgBody, true);
$transparent = imagecolorallocatealpha($imgBody, 0, 0, 0, 127);
imagefill($imgBody, 0, 0, $transparent);
// Head (and hat, of course)
imagecopyresized($imgBody, $imgSkin, $armWidth, 0, 8, 8, $bodyWidth, $bodyWidth, 8, 8);
if ($hat) {
$imgHat = imagecreatetruecolor($bodyWidth, $bodyWidth);
imagecolortransparent($imgHat, $transparency);
imagecopy($imgBody, $imgHat, 0, 0, $armWidth, 0, $bodyWidth, $bodyWidth);
imagecopyresized($imgHat, $imgSkin, $armWidth, 0, 40, 8, $bodyWidth, $bodyWidth, 8, 8);
/*$rgb = imagecolorallocatealpha( $imgHat, 0, 0, 0, 127 );
imagefill( $imgHat, 0, 0, $rgb );*/
}
// Body
imagecopyresized($imgBody, $imgSkin, $armWidth, $bodyWidth, 20, 20, $bodyWidth, $bodyHeight, 8, 12);
// Arms
imagecopyresized($imgBody, $imgSkin, $armWidth + $bodyWidth, $bodyWidth, 44, 20, $armWidth, $bodyHeight, 4, 12);
imagecopyresized($imgBody, $imgSkin, 0, $bodyWidth, 44, 20, $armWidth, $bodyHeight, 4, 12);
// Legs
/**
* X: 4
* Y: 20
*/
imagecopyresized($imgBody, $imgSkin, $armWidth, $bodyWidth + $bodyHeight, 4, 20, $armWidth, $bodyHeight, 4, 12);
$imgLeftLeg = imagecreatetruecolor($armWidth, $bodyHeight);
imagecopyresized($imgLeftLeg, $imgSkin, 0, 0, 4, 20, $armWidth, $bodyHeight, 4, 12);
imageflip($imgLeftLeg, IMG_FLIP_HORIZONTAL);
imagecopy($imgBody, $imgLeftLeg, $bodyWidth, $bodyWidth + $bodyHeight, 0, 0, $armWidth, $bodyHeight);
imagedestroy($imgLeftLeg);
header('Content-type: image/png');
imagepng($imgBody);
imagedestroy($imgSkin);
imagedestroy($imgBody);
}
示例6: flip
/**
* @inheritdoc
*/
public function flip($flipVertical, $flipHorizontal)
{
if (!$flipVertical && !$flipHorizontal) {
return $this;
}
if (function_exists('imageflip')) {
if ($flipVertical && $flipHorizontal) {
$flipMode = \IMG_FLIP_BOTH;
} else {
if ($flipVertical && !$flipHorizontal) {
$flipMode = \IMG_FLIP_VERTICAL;
} else {
if (!$flipVertical && $flipHorizontal) {
$flipMode = \IMG_FLIP_HORIZONTAL;
}
}
}
imageflip($this->resource, $flipMode);
} else {
$width = $this->width();
$height = $this->height();
$src_x = 0;
$src_y = 0;
$src_width = $width;
$src_height = $height;
if ($flipVertical) {
$src_y = $height - 1;
$src_height = -$height;
}
if ($flipHorizontal) {
$src_x = $width - 1;
$src_width = -$width;
}
$imgdest = imagecreatetruecolor($width, $height);
imagealphablending($imgdest, false);
imagesavealpha($imgdest, true);
if (imagecopyresampled($imgdest, $this->resource, 0, 0, $src_x, $src_y, $width, $height, $src_width, $src_height)) {
imagedestroy($this->resource);
$this->resource = $imgdest;
}
}
return $this;
}
示例7: rotate
/**
* rotate image
* @param integer|string $degree degree of rotation. (0, 90, 180, 270). for php < 5.5, you cannot use flip hor, vrt, horvrt
* @return boolean
*/
public function rotate($degree = '90')
{
// if constructor failed to load.
if (!$this->checkConstructorLoad()) {
return false;
}
// check degree
$allowed_degree = array(0, 90, 180, 270, 'hor', 'vrt', 'horvrt');
if (!in_array($degree, $allowed_degree)) {
$degree = 90;
}
if (!is_int($degree) && $degree != 'hor' && $degree != 'vrt' && $degree != 'horvrt') {
$degree = (int) $degree;
}
unset($allowed_degree);
// if image content not set, set it up (this case just call crop without resize).
if ($this->new_img_content == null) {
$result = $this->setImageContent();
if ($result === false) {
$this->status = false;
$this->status_msg = 'Failed to set image content.';
return false;
}
$new_img_content = $this->new_img_content;
unset($result);
} else {
$new_img_content = $this->new_img_object;
}
// rotate.
if (is_int($degree)) {
// rotate by degrees number
switch ($this->original_img_ext) {
case '1':
// gif
// gif
case '2':
// jpg
$rotate = imagerotate($new_img_content, $degree, 0);
break;
case '3':
// png
$rotate = imagerotate($new_img_content, $degree, imageColorAllocateAlpha($new_img_content, 0, 0, 0, 127));
imagealphablending($rotate, false);
imagesavealpha($rotate, true);
break;
default:
// not allowed image type.
$this->status = false;
$this->status_msg = 'Unable to rotate this type of image.';
return false;
break;
}
$this->new_img_object = $rotate;
$this->new_img_height = imagesy($rotate);
$this->new_img_width = imagesx($rotate);
// re-set original image height & width. because image was rotate
$this->original_img_height = $this->new_img_height;
$this->original_img_width = $this->new_img_width;
} else {
// if php version lower than 5.5
if (phpversion() < 5.5) {
$this->status = false;
$this->status_msg = 'Unable to flip image using PHP older than 5.5.';
return false;
}
if ($degree == 'hor') {
$mode = IMG_FLIP_HORIZONTAL;
} elseif ($degree == 'vrt') {
$mode = IMG_FLIP_VERTICAL;
} else {
$mode = IMG_FLIP_BOTH;
}
// flip image.
imageflip($new_img_content, $mode);
unset($mode);
$this->new_img_object = $new_img_content;
$this->new_img_height = imagesy($new_img_content);
$this->new_img_width = imagesx($new_img_content);
// re-set original image height & width. because image was rotate
$this->original_img_height = $this->new_img_height;
$this->original_img_width = $this->new_img_width;
}
return true;
}
示例8: getFlippedGdResource
/**
* Flip the image
* @param resource $srcResource the image resource
* @param int $mode flip mode
* @return resource the flipped resource
*/
public function getFlippedGdResource($srcResource, $mode)
{
imageflip($srcResource, $mode);
return $srcResource;
}
示例9: print_thumbnail
//.........这里部分代码省略.........
$width2 = $width;
$width = $height;
$height = $width2;
}
//Now lets resize it
//First lets create a new image handler which will be the thumbnailed image
$thumbnail = imagecreatetruecolor($width, $height);
if (!$thumbnail) {
return $this->set_error("Method print_thumbnail: A thumbnail image '{$image}' could not be created");
}
/* Image Format Special Handlinng */
//GIF truecolour to palette - preserve transparency
if ($format == 1) {
imagetruecolortopalette($handle, true, 256);
}
//PNG Alpha Channel saving
if ($format == 3) {
//Set to save alpha channel info in source and destination
imagealphablending($handle, false);
imagesavealpha($handle, true);
imagealphablending($thumbnail, false);
imagesavealpha($thumbnail, true);
}
//Resize it
if (!$this->fastimagecopyresampled($thumbnail, $handle, 0, 0, 0, 0, $width, $height, ImageSX($handle), ImageSY($handle), $this->thumb_quality)) {
return $this->set_error("Method print_thumbnail: Failed resizing image '{$image}'.");
}
// Rotate if JPEG and Exif Information is available
$orientation = $this->exiforientation($image, true);
if ($this->rotationsupported($orientation)) {
switch ($orientation) {
case 2:
// mirror horizontal
@imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
break;
case 3:
// rotate 180
$thumbnail = @imagerotate($thumbnail, 180, imagecolorallocate($thumbnail, 255, 255, 255));
break;
case 4:
// mirror vertical
@imageflip($thumbnail, IMG_FLIP_VERTICAL);
break;
case 5:
// mirror horizontal, 90 rotate left
@imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
$thumbnail = @imagerotate($thumbnail, 90, imagecolorallocate($thumbnail, 255, 255, 255));
break;
case 6:
// 90 rotate right
$thumbnail = @imagerotate($thumbnail, -90, imagecolorallocate($thumbnail, 255, 255, 255));
break;
case 7:
// mirror horizontal, 90 rotate right
@imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
$thumbnail = @imagerotate($thumbnail, -90, imagecolorallocate($thumbnail, 255, 255, 255));
break;
case 8:
// 90 rotate left
$thumbnail = @imagerotate($thumbnail, 90, imagecolorallocate($thumbnail, 255, 255, 255));
break;
}
}
//Cache it
if ($this->is_cacheable()) {
switch ($format) {
示例10: imageCreateJpegfromExif
public function imageCreateJpegfromExif($filename)
{
$img = imagecreatefromjpeg($filename);
$exif = exif_read_data($filename);
if (!$exif || !isset($exif['Orientation'])) {
return $img;
}
$orientation = $exif['Orientation'];
if ($orientation === 6 || $orientation === 5) {
$img = imagerotate($img, 270, null);
} else {
if ($orientation === 3 || $orientation === 4) {
$img = imagerotate($img, 180, null);
} else {
if ($orientation === 8 || $orientation === 7) {
$img = imagerotate($img, 90, null);
}
}
}
if ($orientation === 5 || $orientation === 4 || $orientation === 7) {
imageflip($img, IMG_FLIP_HORIZONTAL);
}
return $img;
}
示例11: flipImg
function flipImg($imgPathName)
{
$filename = $imgPathName;
#$this->CI->dir_lib->getImgRdir().$this->lastLoadImgName;
preg_match("#\\.([a-z]{3,4})\$#", $filename, $arr);
if (isset($arr[1]) && !empty($arr[1])) {
switch ($arr[1]) {
case 'png':
$header = 'image/png';
$createImgFunc = '$im = imagecreatefrompng($filename);';
$outputImgFunc = 'imagepng($im,$filename);';
break;
case 'jpg':
$header = 'image/jpeg';
$createImgFunc = '$im = imagecreatefromjpeg($filename);';
$outputImgFunc = 'imagejpeg($im,$filename,100);';
break;
case 'jpeg':
$header = 'image/jpeg';
$createImgFunc = '$im = imagecreatefromjpeg($filename);';
$outputImgFunc = 'imagejpeg($im,$filename,100);';
break;
default:
$header = false;
}
}
if (!$header) {
return false;
}
// Load
eval($createImgFunc);
// Flip it horizontally
imageflip($im, IMG_FLIP_HORIZONTAL);
// Output
eval($outputImgFunc);
imagedestroy($im);
}
示例12: rotate
/**
* {@inheritDoc}
*/
public function rotate($degree = 90)
{
if (false === $this->isClassSetup()) {
return false;
}
// check degree
$allowed_flip = array('hor', 'vrt', 'horvrt');
if (is_numeric($degree)) {
$degree = intval($degree);
} elseif (!is_numeric($degree) && !in_array($degree, $allowed_flip)) {
$degree = 90;
}
unset($allowed_flip);
// setup source image object
if (false === $this->setupSourceImageObject()) {
return false;
}
// check previous step contain errors?
if ($this->isPreviousError() === true) {
return false;
}
// begins rotate.
if (is_int($degree)) {
// rotate by degree
switch ($this->source_image_type) {
case '1':
// gif
// set source image width and height
$source_image_width = imagesx($this->source_image_object);
$source_image_height = imagesy($this->source_image_object);
$this->destination_image_object = imagecreatetruecolor($source_image_width, $source_image_height);
$transwhite = imagecolorallocatealpha($this->destination_image_object, 255, 255, 255, 127);
imagefill($this->destination_image_object, 0, 0, $transwhite);
imagecolortransparent($this->destination_image_object, $transwhite);
imagecopy($this->destination_image_object, $this->source_image_object, 0, 0, 0, 0, $source_image_width, $source_image_height);
$this->destination_image_object = imagerotate($this->destination_image_object, $degree, $transwhite);
unset($source_image_height, $source_image_width, $transwhite);
break;
case '2':
// jpg
$white = imagecolorallocate($this->source_image_object, 255, 255, 255);
$this->destination_image_object = imagerotate($this->source_image_object, $degree, $white);
unset($white);
break;
case '3':
// png
$transwhite = imageColorAllocateAlpha($this->source_image_object, 0, 0, 0, 127);
$this->destination_image_object = imagerotate($this->source_image_object, $degree, $transwhite);
imagealphablending($this->destination_image_object, false);
imagesavealpha($this->destination_image_object, true);
unset($transwhite);
break;
default:
$this->status = false;
$this->status_msg = 'Unable to rotate this kind of image.';
return false;
}
$this->destination_image_height = imagesy($this->destination_image_object);
$this->destination_image_width = imagesx($this->destination_image_object);
$this->source_image_height = $this->destination_image_height;
$this->source_image_width = $this->destination_image_width;
} else {
// flip image
if (version_compare(phpversion(), '5.5', '<')) {
$this->status = false;
$this->status_msg = 'Unable to flip image using PHP older than 5.5.';
return false;
}
if ($degree == 'hor') {
$mode = IMG_FLIP_HORIZONTAL;
} elseif ($degree == 'vrt') {
$mode = IMG_FLIP_VERTICAL;
} else {
$mode = IMG_FLIP_BOTH;
}
// flip image.
imageflip($this->source_image_object, $mode);
unset($mode);
$this->destination_image_object = $this->source_image_object;
$this->destination_image_height = imagesy($this->source_image_object);
$this->destination_image_width = imagesx($this->source_image_object);
$this->source_image_height = $this->destination_image_height;
$this->source_image_width = $this->destination_image_width;
}
// clear
if (get_resource_type($this->source_image_object) === 'gd') {
if ($this->source_image_object != $this->destination_image_object) {
imagedestroy($this->source_image_object);
}
$this->source_image_object = null;
}
if (!$this->isPreviousError()) {
$this->status = true;
$this->status_msg = null;
}
return true;
}
示例13: __image_flip
function __image_flip($img, $mode)
{
if (function_exists("imageflip")) {
return imageflip($img, $mode);
}
$width = imagesx($img);
$height = imagesy($img);
$src_x = 0;
$src_y = 0;
$src_width = $width;
$src_height = $height;
switch ($mode) {
case FLIP_HORIZONTAL:
$src_x = $width - 1;
$src_width = -$width;
break;
case FLIP_VERTICAL:
$src_y = $height - 1;
$src_height = -$height;
break;
case FLIP_BOTH:
$src_x = $width - 1;
$src_y = $height - 1;
$src_width = -$width;
$src_height = -$height;
break;
default:
return $img;
}
$img_new = imagecreatetruecolor($width, $height);
return imagecopyresampled($img_new, $img, 0, 0, $src_x, $src_y, $width, $height, $src_width, $src_height) ? $img_new : $img;
}
示例14: draw
/**
* draw icon to internal buffer
* @param string $hash
* @return $this
*/
public function draw($hash)
{
$index = 0;
$tiles = $this->tiles;
$tileSize = $this->tileSize;
$tile = $this->tile;
$tile->allocate($tileSize);
$br = $tileSize * ($tiles - 1);
$offsets = array(array(0, 0, 0, 1, 1, 0), array($br, 0, -1, 0, 0, 1), array($br, $br, 0, -1, -1, 0), array(0, $br, 1, 0, 0, -1), array($br, 0, 0, 1, -1, 0), array($br, $br, -1, 0, 0, -1), array(0, $br, 0, -1, 1, 0), array(0, 0, 1, 0, 0, 1));
if (!$this->image) {
$this->image = $image = imagecreatetruecolor($tileSize * $tiles, $tileSize * $tiles);
$this->white = imagecolorallocate($image, 255, 255, 255);
}
$image = $this->image;
$white = $this->white;
$xEnd = $tiles + 1 >> 1;
$xMid = $xEnd + 1 >> 1;
$center = $tiles & 1 ? $tiles >> 1 : -1;
$numColors = $this->colors;
assert('$this->getMinimumHashLength() <= strlen($hash)');
$colors = array();
for ($i = 0; $i < $numColors; $i++) {
$r = hexdec(substr($hash, $index, 2));
$index += 2;
$g = hexdec(substr($hash, $index, 2));
$index += 2;
$b = hexdec(substr($hash, $index, 2));
$index += 2;
$colors[] = $tile->getColor($r, $g, $b);
}
$baseColor = hexdec($hash[$index++]);
$colorPattern = hexdec($hash[$index++]);
$type = hexdec($hash[$index++]);
for ($x = 0; $x < $xEnd; $x++) {
$xOffsets = $offsets;
for ($y = 0; $y <= $x; $y++) {
$color = $baseColor;
if ($colorPattern & 1) {
$color++;
}
if ($colorPattern & 2) {
$color += $x;
}
if ($colorPattern & 4) {
$color += $y;
}
if ($colorPattern & 8) {
$color += $x <= $xMid;
}
$type += hexdec($hash[$index++]);
$tileImage = $tile->draw($type, $colors[$color % $numColors]);
for ($i = 0; $i < 8; $i++) {
if ($i == 4 && ($y == $x || $x == 0)) {
break;
}
$offset = $xOffsets[$i];
if ($i < 4 || $x != $center) {
if ($i == 4) {
imageflip($tileImage, IMG_FLIP_HORIZONTAL);
}
imagecopy($image, $tileImage, $offset[0], $offset[1], 0, 0, $tileSize, $tileSize);
if ($x == $center && $y == $center) {
break;
}
if ($i != 7) {
$tileImage = imagerotate($tileImage, 270, $white);
}
}
$xOffsets[$i][0] += $offset[2] * $tileSize;
$xOffsets[$i][1] += $offset[3] * $tileSize;
}
}
for ($i = 0; $i < 8; $i++) {
$offsets[$i][0] += $offsets[$i][4] * $tileSize;
$offsets[$i][1] += $offsets[$i][5] * $tileSize;
}
}
return $this;
}
示例15: wppa_orientate_image_file
function wppa_orientate_image_file($file, $ori)
{
// Validate args
if (!is_file($file)) {
wppa_log('Err', 'File not found (wppa_orientate_image_file())');
return false;
}
if (!wppa_is_int($ori) || $ori < '2' || $ori > '8') {
wppa_log('Err', 'Bad arg $ori:' . $ori . ' (wppa_orientate_image_file())');
return false;
}
// Load image
$source = wppa_imagecreatefromjpeg($file);
if (!$source) {
wppa_log('Err', 'Could not create memoryimage from jpg file ' . $file);
return false;
}
// Perform operation
switch ($ori) {
case '2':
$orientate = $source;
imageflip($orientate, IMG_FLIP_HORIZONTAL);
break;
case '3':
$orientate = imagerotate($source, 180, 0);
break;
case '4':
$orientate = $source;
imageflip($orientate, IMG_FLIP_VERTICAL);
break;
case '5':
$orientate = imagerotate($source, 270, 0);
imageflip($orientate, IMG_FLIP_HORIZONTAL);
break;
case '6':
$orientate = imagerotate($source, 270, 0);
break;
case '7':
$orientate = imagerotate($source, 90, 0);
imageflip($orientate, IMG_FLIP_HORIZONTAL);
break;
case '8':
$orientate = imagerotate($source, 90, 0);
break;
}
// Output
imagejpeg($orientate, $file, wppa_opt('jpeg_quality'));
// Accessable
wppa_chmod($file);
// Optimized
wppa_optimize_image_file($file);
// Free the memory
imagedestroy($source);
@imagedestroy($orientate);
// Done
return true;
}