Imagick::cropImage - Manual - PHP

update page now
  • Downloads
  • Documentation
  • Get Involved
  • Help
  • PHP 8.5
Search docs PHP 8.1.34 Released! Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box Imagick::cropThumbnailImage » « Imagick::count
  • PHP 手册
  • 函数参考
  • 图像生成和处理
  • ImageMagick
  • Imagick
切换语言: English German Spanish French Italian Japanese Brazilian Portuguese Russian Turkish Ukrainian Chinese (Simplified) Other Imagick::cropImage

(PECL imagick 2, PECL imagick 3)

Imagick::cropImage截图图片的一块区域

说明

public Imagick::cropImage( int $width, int $height, int $x, int $y): bool

截图图片的一块区域

参数

width

截图的宽度

height

截图的高度

x

裁剪区域左上角的 X 轴坐标(以原图的左上角为原点)

y

裁剪区域左上角的 X 轴坐标(以原图的左上角为原点)

返回值

成功时返回 true

错误/异常

错误时抛出 ImagickException。

示例

示例 #1 Imagick::cropImage()

<?phpfunction cropImage($imagePath, $startX, $startY, $width, $height) { $imagick = new \Imagick(realpath($imagePath)); $imagick->cropImage($width, $height, $startX, $startY); header("Content-Type: image/jpg"); echo $imagick->getImageBlob();}?>

发现了问题?

了解如何改进此页面 • 提交拉取请求 • 报告一个错误 +添加备注

用户贡献的备注 4 notes

up down 17 Christian Dehning15 years ago When cropping gif-images (I had no problems with jpg and png images), the canvas is not removed. Please run the following command on the cropped gif, to remove the blank space: $im->setImagePage(0, 0, 0, 0); up down 5 olav at schettler dot net9 years ago Here is a simple function to create a thumbnail. It accepts an additional parameter to set the focus point of the generated thumbnail: <?php function thumbnail($image, $new_w, $new_h, $focus = 'center') { $w = $image->getImageWidth(); $h = $image->getImageHeight(); if ($w > $h) { $resize_w = $w * $new_h / $h; $resize_h = $new_h; } else { $resize_w = $new_w; $resize_h = $h * $new_w / $w; } $image->resizeImage($resize_w, $resize_h, Imagick::FILTER_LANCZOS, 0.9); switch ($focus) { case 'northwest': $image->cropImage($new_w, $new_h, 0, 0); break; case 'center': $image->cropImage($new_w, $new_h, ($resize_w - $new_w) / 2, ($resize_h - $new_h) / 2); break; case 'northeast': $image->cropImage($new_w, $new_h, $resize_w - $new_w, 0); break; case 'southwest': $image->cropImage($new_w, $new_h, 0, $resize_h - $new_h); break; case 'southeast': $image->cropImage($new_w, $new_h, $resize_w - $new_w, $resize_h - $new_h); break; } } ?> up down 5 ElPadre15 years ago Actually, the Imagick::setImagePage(0,0,0,0) is also handy with jpgs and pngs, if you plan to do any more changes on the cropped image that involves positioning and/or gravity (I created a script that does crop, face blur and watermarking in one go, and had a hell of a time determining why the blurs and the watermark text never showed up...). up down -2 oxxido at gmail dot com10 years ago I have a function that takes an image, resize and crop it, and save it as normal, then resize it again and crop it again to create the thumbnail. The numbers of the second crop were WAY off, and the calculations were perfect, the problem, was the second crop wasn't resetting the imagePage, so if you try to crop the same image twice, it will be a good idea to reset it first: <?php $thumb = new Imagick($file) $thumb->resizeImage($r_w1,$r_h1,Imagick::FILTER_CATROM,0.9, false); $thumb->cropImage($w1,$h1,$l1,$t1); $thumb->writeImage($destinationPath.'/'.$fileName); $thumb->resizeImage($r_w2,$r_h2,Imagick::FILTER_CATROM,0.9, false); $thumb->setImagePage(0, 0, 0, 0); $thumb->cropImage($w2,$h2,$l2,$t2); $thumb->writeImage($destinationPath.'/'.$fileNameThumb); ?> BTW, i needed perfect dimentions so i had to set the "bestfit" to false. +添加备注
  • Imagick
    • adaptiveBlurImage
    • adaptiveResizeImage
    • adaptiveSharpenImage
    • adaptiveThresholdImage
    • addImage
    • addNoiseImage
    • affineTransformImage
    • animateImages
    • annotateImage
    • appendImages
    • autoLevelImage
    • blackThresholdImage
    • blueShiftImage
    • blurImage
    • borderImage
    • brightnessContrastImage
    • charcoalImage
    • chopImage
    • clampImage
    • clear
    • clipImage
    • clipImagePath
    • clipPathImage
    • clutImage
    • coalesceImages
    • colorizeImage
    • colorMatrixImage
    • combineImages
    • commentImage
    • compareImageChannels
    • compareImageLayers
    • compareImages
    • compositeImage
    • _​_​construct
    • contrastImage
    • contrastStretchImage
    • convolveImage
    • count
    • cropImage
    • cropThumbnailImage
    • current
    • cycleColormapImage
    • decipherImage
    • deconstructImages
    • deleteImageArtifact
    • deleteImageProperty
    • deskewImage
    • despeckleImage
    • destroy
    • displayImage
    • displayImages
    • distortImage
    • drawImage
    • edgeImage
    • embossImage
    • encipherImage
    • enhanceImage
    • equalizeImage
    • evaluateImage
    • exportImagePixels
    • extentImage
    • flipImage
    • floodFillPaintImage
    • flopImage
    • forwardFourierTransformImage
    • frameImage
    • functionImage
    • fxImage
    • gammaImage
    • gaussianBlurImage
    • getColorspace
    • getCompression
    • getCompressionQuality
    • getCopyright
    • getFilename
    • getFont
    • getFormat
    • getGravity
    • getHomeURL
    • getImage
    • getImageAlphaChannel
    • getImageArtifact
    • getImageBackgroundColor
    • getImageBlob
    • getImageBluePrimary
    • getImageBorderColor
    • getImageChannelDepth
    • getImageChannelDistortion
    • getImageChannelDistortions
    • getImageChannelKurtosis
    • getImageChannelMean
    • getImageChannelRange
    • getImageChannelStatistics
    • getImageColormapColor
    • getImageColors
    • getImageColorspace
    • getImageCompose
    • getImageCompression
    • getImageCompressionQuality
    • getImageDelay
    • getImageDepth
    • getImageDispose
    • getImageDistortion
    • getImageFilename
    • getImageFormat
    • getImageGamma
    • getImageGeometry
    • getImageGravity
    • getImageGreenPrimary
    • getImageHeight
    • getImageHistogram
    • getImageInterlaceScheme
    • getImageInterpolateMethod
    • getImageIterations
    • getImageLength
    • getImageMimeType
    • getImageOrientation
    • getImagePage
    • getImagePixelColor
    • getImageProfile
    • getImageProfiles
    • getImageProperties
    • getImageProperty
    • getImageRedPrimary
    • getImageRegion
    • getImageRenderingIntent
    • getImageResolution
    • getImagesBlob
    • getImageScene
    • getImageSignature
    • getImageTicksPerSecond
    • getImageTotalInkDensity
    • getImageType
    • getImageUnits
    • getImageVirtualPixelMethod
    • getImageWhitePoint
    • getImageWidth
    • getInterlaceScheme
    • getIteratorIndex
    • getNumberImages
    • getOption
    • getPackageName
    • getPage
    • getPixelIterator
    • getPixelRegionIterator
    • getPointSize
    • getQuantum
    • getQuantumDepth
    • getQuantumRange
    • getRegistry
    • getReleaseDate
    • getResource
    • getResourceLimit
    • getSamplingFactors
    • getSize
    • getSizeOffset
    • getVersion
    • haldClutImage
    • hasNextImage
    • hasPreviousImage
    • identifyFormat
    • identifyImage
    • implodeImage
    • importImagePixels
    • inverseFourierTransformImage
    • labelImage
    • levelImage
    • linearStretchImage
    • liquidRescaleImage
    • listRegistry
    • magnifyImage
    • mergeImageLayers
    • minifyImage
    • modulateImage
    • montageImage
    • morphImages
    • morphology
    • motionBlurImage
    • negateImage
    • newImage
    • newPseudoImage
    • nextImage
    • normalizeImage
    • oilPaintImage
    • opaquePaintImage
    • optimizeImageLayers
    • pingImage
    • pingImageBlob
    • pingImageFile
    • polaroidImage
    • posterizeImage
    • previewImages
    • previousImage
    • profileImage
    • quantizeImage
    • quantizeImages
    • queryFontMetrics
    • queryFonts
    • queryFormats
    • raiseImage
    • randomThresholdImage
    • readImage
    • readImageBlob
    • readImageFile
    • readimages
    • remapImage
    • removeImage
    • removeImageProfile
    • render
    • resampleImage
    • resetImagePage
    • resizeImage
    • rollImage
    • rotateImage
    • rotationalBlurImage
    • sampleImage
    • scaleImage
    • segmentImage
    • selectiveBlurImage
    • separateImageChannel
    • sepiaToneImage
    • setBackgroundColor
    • setColorspace
    • setCompression
    • setCompressionQuality
    • setFilename
    • setFirstIterator
    • setFont
    • setFormat
    • setGravity
    • setImage
    • setImageAlphaChannel
    • setImageArtifact
    • setImageBackgroundColor
    • setImageBluePrimary
    • setImageBorderColor
    • setImageChannelDepth
    • setImageColormapColor
    • setImageColorspace
    • setImageCompose
    • setImageCompression
    • setImageCompressionQuality
    • setImageDelay
    • setImageDepth
    • setImageDispose
    • setImageExtent
    • setImageFilename
    • setImageFormat
    • setImageGamma
    • setImageGravity
    • setImageGreenPrimary
    • setImageInterlaceScheme
    • setImageInterpolateMethod
    • setImageIterations
    • setImageMatte
    • setImageOrientation
    • setImagePage
    • setImageProfile
    • setImageProperty
    • setImageRedPrimary
    • setImageRenderingIntent
    • setImageResolution
    • setImageScene
    • setImageTicksPerSecond
    • setImageType
    • setImageUnits
    • setImageVirtualPixelMethod
    • setImageWhitePoint
    • setInterlaceScheme
    • setIteratorIndex
    • setLastIterator
    • setOption
    • setPage
    • setPointSize
    • setProgressMonitor
    • setRegistry
    • setResolution
    • setResourceLimit
    • setSamplingFactors
    • setSize
    • setSizeOffset
    • setType
    • shadeImage
    • shadowImage
    • sharpenImage
    • shaveImage
    • shearImage
    • sigmoidalContrastImage
    • sketchImage
    • smushImages
    • solarizeImage
    • sparseColorImage
    • spliceImage
    • spreadImage
    • statisticImage
    • steganoImage
    • stereoImage
    • stripImage
    • subImageMatch
    • swirlImage
    • textureImage
    • thresholdImage
    • thumbnailImage
    • tintImage
    • _​_​toString
    • transformImageColorspace
    • transparentPaintImage
    • transposeImage
    • transverseImage
    • trimImage
    • uniqueImageColors
    • unsharpMaskImage
    • valid
    • vignetteImage
    • waveImage
    • whiteThresholdImage
    • writeImage
    • writeImageFile
    • writeImages
    • writeImagesFile
  • Deprecated
    • averageImages
    • clone
    • colorFloodfillImage
    • filter
    • flattenImages
    • getImageAttribute
    • getImageChannelExtrema
    • getImageClipMask
    • getImageExtrema
    • getImageIndex
    • getImageMatte
    • getImageMatteColor
    • getImageSize
    • mapImage
    • matteFloodfillImage
    • medianFilterImage
    • mosaicImages
    • orderedPosterizeImage
    • paintFloodfillImage
    • paintOpaqueImage
    • paintTransparentImage
    • radialBlurImage
    • recolorImage
    • reduceNoiseImage
    • roundCorners
    • setImageAttribute
    • setImageBias
    • setImageBiasQuantum
    • setImageClipMask
    • setImageIndex
    • setImageMatteColor
    • setImageOpacity
    • transformImage
To Top ↑ and ↓ to navigate • Enter to select • Esc to close • / to open Press Enter without selection to search using Google

Từ khóa » T2 Thumb Gif