Esempio n. 1
0
$Image->save($file_name);
$Image->clear();
echo '<a href="' . $file_name . '">' . $file_ext . '</a><img src="' . $file_name . '" alt="" class="thumbnail"> ';
unset($file_name, $Image);
// -------------------------------------------------------------------------------------------------------------------
?>
        <h2>Animated GIF</h2>
        <?php 
echo '<a href="' . $source_image_animated_gif . '">source image</a><img src="' . $source_image_animated_gif . '" alt="" class="thumbnail"><br>' . "\n";
echo 'Save as: ' . "\n";
$Image = new \Rundiz\Image\Drivers\Imagick($source_image_animated_gif);
$file_ext = 'jpg';
$file_name = $base_save_file_name . '-sourceanimatedgif.' . $file_ext;
$Image->resizeNoRatio($resize_w, $resize_h);
$Image->rotate($rotate);
$Image->crop($crop_width, $crop_height);
$Image->save($file_name);
$Image->clear();
echo '<a href="' . $file_name . '">' . $file_ext . '</a><img src="' . $file_name . '" alt="" class="thumbnail"> ';
$file_ext = 'png';
$file_name = $base_save_file_name . '-sourceanimatedgif.' . $file_ext;
$Image->resizeNoRatio($resize_w, $resize_h);
$Image->rotate($rotate);
$Image->crop($crop_width, $crop_height);
$Image->save($file_name);
$Image->clear();
echo '<a href="' . $file_name . '">' . $file_ext . '</a><img src="' . $file_name . '" alt="" class="thumbnail"> ';
$file_ext = 'gif';
$file_name = $base_save_file_name . '-sourceanimatedgif.' . $file_ext;
$Image->resizeNoRatio($resize_w, $resize_h);
$Image->rotate($rotate);
Esempio n. 2
0
function displayTestCrop(array $test_data_set)
{
    $test_crop = array(array(0, 0, 'transparent'), array(90, 90, 'black'), array('center', 'middle', 'white'));
    echo '<h2>Crop the images</h2>' . "\n";
    if (is_array($test_data_set)) {
        foreach ($test_data_set as $img_type_name => $item) {
            echo '<h3>' . $img_type_name . '</h3>' . "\n";
            if (is_array($item) && array_key_exists('source_image_path', $item)) {
                echo 'Source image: <a href="' . $item['source_image_path'] . '"><img src="' . $item['source_image_path'] . '" alt="" class="thumbnail"></a><br>' . "\n";
                $Image = new \Rundiz\Image\Drivers\Imagick($item['source_image_path']);
                $source_image_exp = explode('.', $item['source_image_path']);
                $file_ext = '.';
                if (is_array($source_image_exp)) {
                    $file_ext .= $source_image_exp[count($source_image_exp) - 1];
                }
                unset($source_image_exp);
                foreach ($test_crop as $crop_xy) {
                    if (isset($crop_xy[0]) && isset($crop_xy[1]) && isset($crop_xy[2])) {
                        $file_name = '../processed-images/rundiz-imagick-image-crop-' . str_replace(' ', '-', strtolower($img_type_name)) . '-900x900-start' . $crop_xy[0] . ',' . $crop_xy[1] . '-fill-' . $crop_xy[2];
                        echo 'Cropping at <a href="' . $file_name . $file_ext . '">' . $crop_xy[0] . ', ' . $crop_xy[1] . '</a> fill ' . $crop_xy[2] . '<img src="' . $file_name . $file_ext . '" alt="" class="thumbnail"><br>' . "\n";
                        $Image->crop(900, 900, $crop_xy[0], $crop_xy[1], $crop_xy[2]);
                        $save_result = $Image->save($file_name . $file_ext);
                        if ($save_result != true) {
                            echo ' &nbsp; &nbsp; Error: ' . $Image->status_msg . '<br>' . "\n";
                        }
                        unset($file_name, $save_result);
                        $Image->clear();
                    }
                }
                // endforeach;
                $Image->crop(2000, 2000, 'center', 'middle', 'white');
                $file_name = '../processed-images/rundiz-imagick-image-crop-' . str_replace(' ', '-', strtolower($img_type_name)) . '-2000x2000-startcenter,middle-fill-white';
                echo 'Cropping at <a href="' . $file_name . $file_ext . '">center, middle</a> (2000x2000) fill white<img src="' . $file_name . $file_ext . '" alt="" class="thumbnail"><br>' . "\n";
                $Image->save($file_name . $file_ext);
                $Image->clear();
                unset($crop_xy, $file_ext, $Image);
            }
            echo "\n\n";
        }
        // endforeach;
    }
    echo "\n\n";
}
Esempio n. 3
0
}
if (is_numeric($start_y)) {
    $start_y = intval($start_y);
}
if (!is_numeric($fontsize)) {
    $fontsize = 15;
} else {
    $fontsize = intval($fontsize);
}
$Image = new \Rundiz\Image\Drivers\Imagick($source_image_file);
switch ($act) {
    case 'watermarktext':
        $Image->watermarkText('Rundiz watermark สั้น ญู ให้ ทดสอบสระ.', '../source-images/cschatthai.ttf', $start_x, $start_y, $fontsize);
        break;
    case 'crop':
        $Image->crop($width, $height);
        break;
    case 'rotate':
        $Image->rotate($degree);
        break;
    case 'resizenoratio':
        $Image->resizeNoRatio($width, $height);
        break;
    case 'resize':
    default:
        $Image->resize($width, $height);
        break;
}
if ($Image->status === false) {
    die($Image->status_msg);
}
Esempio n. 4
0
 /**
  * @depends testRequiredImagickImageMagickPhpVersions
  */
 public function testImagickCrop()
 {
     if (is_array($source_images_set = self::$source_images_set)) {
         $resize_width = 900;
         $resize_height = 600;
         $crop_width = 400;
         $crop_height = 400;
         $crop_x = 'center';
         $crop_y = 'middle';
         foreach ($source_images_set as $source_image) {
             $Image = new \Rundiz\Image\Drivers\Imagick(self::$source_images_dir . $source_image);
             foreach (self::$processed_extensions as $save_extension) {
                 $Image->master_dim = 'auto';
                 $Image->resizeNoRatio($resize_width, $resize_height);
                 $Image->crop($crop_width, $crop_height, $crop_x, $crop_y);
                 $save_file_name = self::$processed_images_dir . 'rundiz-imagick-source[' . $this->getExtensionFromName($source_image) . ']-masterdim[' . $Image->master_dim . ']-resizeNoRatio[' . $resize_width . 'x' . $resize_height . ']-crop[' . $crop_width . 'x' . $crop_height . '-' . $crop_x . ',' . $crop_y . ']' . '.' . $save_extension;
                 $Image->save($save_file_name);
                 $Image->clear();
                 list($width, $height, $image_type) = getimagesize($save_file_name);
                 $processed_image_data = array('width' => $width, 'image_type' => $image_type);
                 // test assert.
                 $this->assertArraySubset(array('width' => $crop_width, 'image_type' => $this->getProcessedExtensionTypeNumber($save_extension)), $processed_image_data, '', sprintf('Expected result was not matched. %s', var_export($processed_image_data, true)));
                 unset($height, $width, $image_type, $save_file_name);
             }
             // endforeach;
             unset($save_extension);
         }
         // endforeach;
         unset($source_image);
         unset($crop_height, $crop_width, $crop_x, $crop_y, $resize_height, $resize_width, $source_images_set);
     }
 }