本文整理汇总了PHP中_flip_image_resource函数的典型用法代码示例。如果您正苦于以下问题:PHP _flip_image_resource函数的具体用法?PHP _flip_image_resource怎么用?PHP _flip_image_resource使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_flip_image_resource函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: image_edit_apply_changes
/**
* Performs group of changes on Editor specified.
*
* @since 2.9.0
*
* @param WP_Image_Editor $image {@see WP_Image_Editor} instance.
* @param array $changes Array of change operations.
* @return WP_Image_Editor {@see WP_Image_Editor} instance with changes applied.
*/
function image_edit_apply_changes($image, $changes)
{
if (is_resource($image)) {
_deprecated_argument(__FUNCTION__, '3.5', __('$image needs to be an WP_Image_Editor object'));
}
if (!is_array($changes)) {
return $image;
}
// Expand change operations.
foreach ($changes as $key => $obj) {
if (isset($obj->r)) {
$obj->type = 'rotate';
$obj->angle = $obj->r;
unset($obj->r);
} elseif (isset($obj->f)) {
$obj->type = 'flip';
$obj->axis = $obj->f;
unset($obj->f);
} elseif (isset($obj->c)) {
$obj->type = 'crop';
$obj->sel = $obj->c;
unset($obj->c);
}
$changes[$key] = $obj;
}
// Combine operations.
if (count($changes) > 1) {
$filtered = array($changes[0]);
for ($i = 0, $j = 1, $c = count($changes); $j < $c; $j++) {
$combined = false;
if ($filtered[$i]->type == $changes[$j]->type) {
switch ($filtered[$i]->type) {
case 'rotate':
$filtered[$i]->angle += $changes[$j]->angle;
$combined = true;
break;
case 'flip':
$filtered[$i]->axis ^= $changes[$j]->axis;
$combined = true;
break;
}
}
if (!$combined) {
$filtered[++$i] = $changes[$j];
}
}
$changes = $filtered;
unset($filtered);
}
// Image resource before applying the changes.
if ($image instanceof WP_Image_Editor) {
/**
* Filter the WP_Image_Editor instance before applying changes to the image.
*
* @since 3.5.0
*
* @param WP_Image_Editor $image WP_Image_Editor instance.
* @param array $changes Array of change operations.
*/
$image = apply_filters('wp_image_editor_before_change', $image, $changes);
} elseif (is_resource($image)) {
/**
* Filter the GD image resource before applying changes to the image.
*
* @since 2.9.0
* @deprecated 3.5.0 Use wp_image_editor_before_change instead.
*
* @param resource $image GD image resource.
* @param array $changes Array of change operations.
*/
$image = apply_filters('image_edit_before_change', $image, $changes);
}
foreach ($changes as $operation) {
switch ($operation->type) {
case 'rotate':
if ($operation->angle != 0) {
if ($image instanceof WP_Image_Editor) {
$image->rotate($operation->angle);
} else {
$image = _rotate_image_resource($image, $operation->angle);
}
}
break;
case 'flip':
if ($operation->axis != 0) {
if ($image instanceof WP_Image_Editor) {
$image->flip(($operation->axis & 1) != 0, ($operation->axis & 2) != 0);
} else {
$image = _flip_image_resource($image, ($operation->axis & 1) != 0, ($operation->axis & 2) != 0);
}
}
//.........这里部分代码省略.........
示例2: image_edit_apply_changes
function image_edit_apply_changes($img, $changes)
{
if (!is_array($changes)) {
return $img;
}
// expand change operations
foreach ($changes as $key => $obj) {
if (isset($obj->r)) {
$obj->type = 'rotate';
$obj->angle = $obj->r;
unset($obj->r);
} elseif (isset($obj->f)) {
$obj->type = 'flip';
$obj->axis = $obj->f;
unset($obj->f);
} elseif (isset($obj->c)) {
$obj->type = 'crop';
$obj->sel = $obj->c;
unset($obj->c);
}
$changes[$key] = $obj;
}
// combine operations
if (count($changes) > 1) {
$filtered = array($changes[0]);
for ($i = 0, $j = 1; $j < count($changes); $j++) {
$combined = false;
if ($filtered[$i]->type == $changes[$j]->type) {
switch ($filtered[$i]->type) {
case 'rotate':
$filtered[$i]->angle += $changes[$j]->angle;
$combined = true;
break;
case 'flip':
$filtered[$i]->axis ^= $changes[$j]->axis;
$combined = true;
break;
}
}
if (!$combined) {
$filtered[++$i] = $changes[$j];
}
}
$changes = $filtered;
unset($filtered);
}
// image resource before applying the changes
$img = apply_filters('image_edit_before_change', $img, $changes);
foreach ($changes as $operation) {
switch ($operation->type) {
case 'rotate':
if ($operation->angle != 0) {
$img = _rotate_image_resource($img, $operation->angle);
}
break;
case 'flip':
if ($operation->axis != 0) {
$img = _flip_image_resource($img, ($operation->axis & 1) != 0, ($operation->axis & 2) != 0);
}
break;
case 'crop':
$sel = $operation->sel;
$scale = 1 / _image_get_preview_ratio(imagesx($img), imagesy($img));
// discard preview scaling
$img = _crop_image_resource($img, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale);
break;
}
}
return $img;
}