'', 'showoriginal' => 'true', 'colorized' => 'true' ), $atts ) ); if(extension_loaded('imagick')) { $img = new Imagick(esc_attr($file)); if($colorized == 'false' || $colorized == '0'){ /* leave hue at 100%, drop saturation by 100%, leave brightness at 100% */ $img->modulateImage(100, 0, 100); } /* Makke a clone of the image, not a reference */ $unscaledImg = clone $img; /* Get the Image Properties */ $imageprops = $img->getImageGeometry(); $imgWidth = $imageprops['width']; $imgHeight = $imageprops['height']; /* Defines the Resolution of the ASCII-Image */ $scaleFactor = 8; /* Calulate the new scaled size */ $imgWidthScaled = floor($imgWidth / $scaleFactor); $imgHeightScaled = floor($imgHeight / $scaleFactor); /* Scale the original image to cluster the Pixels */ $img->resizeImage($imgWidthScaled, $imgHeightScaled, imagick::FILTER_LANCZOS, 1); /* Imagemagick PixelIterator */ $it = $img->getPixelIterator(); $pixelColors = []; /* Loop trough pixel rows */ foreach( $it as $row => $pixels ){ $rowColors = []; /* Loop trough the pixels in the row (columns) */ foreach ( $pixels as $column => $pixel ){ /* getColor returns an rgba-Array */ $color = $pixel->getColor(); array_push($rowColors, $color); } array_push($pixelColors, $rowColors); /* Sync the iterator, this is important to do on each iteration */ $it->syncIterator(); } /* Values for the CSS Style */ $rowHeight = $imgHeight / $imgHeightScaled; $fontSize = ($imgWidth / $imgWidthScaled) * 2; $columnWidth = $imgWidth / $imgWidthScaled; /* return variable */ $ascii = ''; /* Loop trough PixelColors and print each Pixel */ $ascii .= '
"; if($showoriginal == 'true' || $showoriginal == '1'){ $ascii .= sprintf( '