Imagick::getImageUnits

(PECL imagick 2, PECL imagick 3)

Imagick::getImageUnits β€” Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ Π΅Π΄ΠΈΠ½ΠΈΡ†Ρ‹ измСрСния Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΈΡ изобраТСния

ОписаниС

public function Imagick::getImageUnits(): int

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ Π΅Π΄ΠΈΠ½ΠΈΡ†Ρ‹ измСрСния Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΈΡ изобраТСния.

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

Π‘ΠΈΠ³Π½Π°Ρ‚ΡƒΡ€Π° Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π½Π΅ содСрТит ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ².

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ Π΅Π΄ΠΈΠ½ΠΈΡ†Ρ‹ измСрСния Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΈΡ изобраТСния.

Ошибки

Ѐункция выбрасываСт ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ImagickException, Ссли Π²ΠΎΠ·Π½ΠΈΠΊΠ»Π° ошибка.

οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 2 notes

up
1
Victor ΒΆ
8 years ago
Here's an example of how to interpret and use ImageResolution and ImageUnits:

$i = new Imagick('some_image_file.png');

$r = $i->getImageResolution();
$u = $i->getImageUnits();
if ($u == Imagick::RESOLUTION_PIXELSPERCENTIMETER) {
   $r[x] = (int)round($r[x] * 2.54);
   $r[y] = (int)round($r[y] * 2.54);
   $i->setImageUnits(Imagick::RESOLUTION_PIXELSPERINCH);
   $i->setImageResolution($r[x], $r[y]);

  //note that the number type is double again
   $r = $i->getImageResolution();
}
up
0
holdoffhunger at gmail dot com ΒΆ
13 years ago
By using the PHP function for getImageUnits, you get back an integer representing the evaluation of a predefined, PATHUNITS constant of the ImageMagick package.  You only have four values for this.  They look like "imagick::PATHUNITS_UNDEFINED", with _VALUE value's being: undefined, userspace, userspaceonuse, and objectboundingbox.  Undefined, if printed, is a 0, userspace is a 1, userspaceonuse is a 2, and objectboundingbox is a 3.

What's the use of knowing the Clipping Path Unit default for an image?  According to the Wikipedia article for "Clipping Path", a Clipping Path is "a closed vector path, or shape, used to cut out a 2D image in image editing software. Anything inside the path will be included after the clipping path is applied; anything outside the path will be omitted from the output."

The official ImageMagick documentation provides only two valid values coming into or out of the clipping path unit value, one being userSpaceOnUse and the other being ObjectBoundingBox.  The only definitions provided: "If userSpaceOnUse, the contents of the clipping path represent values in the current user coordinate system in place at the time when the clipping path is referenced. if objectBoundingBox, then the user coordinate system for the contents of the clipping path is established using the bounding box of the object to which the clipping path is applied. The default is userSpaceOnUse." http://www.imagemagick.org/RMagick/doc/rvgclip.html

In personal experimentation, all JPEG and GIF files have provided '0' for "Undefined" on this function, and all BMP and PNG files have provided '2' for "UserSpaceOnUse" on this function.

And some sample code :

<?php

            // Author: holdoffhunger@gmail.com
    
        // Imagick Type
        // ---------------------------------------------

    $imagick_type = new Imagick();
    
        // Open File
        // ---------------------------------------------
        
    $file_to_grab = "image_workshop_directory/test.gif";
    
    $file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
    
        // Grab File
        // ---------------------------------------------

    $imagick_type->readImageFile($file_handle_for_viewing_image_file);
    
        // Get Image Units
        // ---------------------------------------------
        
    $image_page = $imagick_type->getImageUnits();
    
        // Interpret Units Value
        // ---------------------------------------------

    switch($image_units)
    {
        case imagick::PATHUNITS_UNDEFINED:
            $image_units_printable = "Undefined";
            break;
            
        case imagick::PATHUNITS_USERSPACE:
            $image_units_printable = "User Space";
            break;
            
        case imagick::PATHUNITS_USERSPACEONUSE:
            $image_units_printable = "User Space On Use";
            break;
            
        case imagick::PATHUNITS_OBJECTBOUNDINGBOX:
            $image_units_printable = "Object Bounding Box";
            break;
    }
    
        // Print Units Value
        // ---------------------------------------------

    print(" Image Units: # $image_units -- $image_units_printable .");

?>