Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
PHP | Gmagick chopimage() Function
Next article icon

PHP | Imagick cropImage() Function

Last Updated : 06 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

The Imagick::cropImage() function is an inbuilt function in PHP which is used to extracts the region of the image.
Syntax: 
 

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


Parameters: This function accept four parameters as mention above and describe below. 
 

  • $width: This parameter is used to specify the width of the cropped image.
  • $height: This parameter is used to specify the height of the cropped image.
  • $x: This parameter is used to specify the X coordinate of the cropped image of top left corner.
  • $y: This parameter is used to specify the Y coordinate of the cropped image of top left corner.


Return Value: This function returns True on success.
Below programs illustrate the Imagick::cropImage() function in PHP:
Original Image: 
 


Program 1: 
 

php

<?php
   
// require_once('path/vendor/autoload.php');
    
// Create an imagick object
 $image = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
    
// Imagick function to crop Image 
$image->cropImage(390, 100, 0, 0);
       
header("Content-Type: image/jpg");
   
// Display the image
echo $image->getImageBlob();
?> 
                      
                       

Output: 
 

 

Original Image: 
 


Program 2: 
 

php

<?php
$string = "Computer Science portal for Geeks!";
  
// creating new image of above String
// and add color and background
$im = new Imagick();
$draw = new ImagickDraw();
 
// Fill the color in image
$draw->setFillColor(new ImagickPixel('green'));
 
// Set the text font size
$draw->setFontSize(50);
 
$matrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($matrix['textWidth'], $matrix['textHeight'],
         new ImagickPixel('white'));
          
// Draw the image        
$im->drawImage($draw);
 
// Set the image format
$im->setImageFormat('png');
  
// Imagick function to crop Image
$im->cropImage(420, 120, 0, 0);
         
header("Content-Type: image/jpg");
     
// Display the image
echo $im->getImageBlob();
?>
                      
                       

Output: 
 


Reference: http://php.net/manual/en/imagick.cropimage.php
 



Next Article
PHP | Gmagick chopimage() Function

R

R_Raj
Improve
Article Tags :
  • PHP
  • Web Technologies
  • Image-Processing
  • PHP-function
  • PHP-Imagick

Similar Reads

  • PHP | Imagick chopImage() Function
    The Imagick::chopImage() function is an inbuilt function in PHP which is used to remove the region of an image and trim it. This function accepts the dimension of image and chops the area and the dimension from where the image is to be trim. Syntax: bool Imagick::chopImage( $width, $height, $x, $y )
    1 min read
  • PHP | Gmagick cropimage() Function
    The Gmagick::cropimage() function is an inbuilt function in PHP which is used to extracts the region of the image. This function crop the part of image. Syntax: public Gmagick::cropimage( $width , $height , $x , $y ) Parameters: This function accept four parameters as mention above and describe belo
    2 min read
  • PHP | Gmagick chopimage() Function
    The Gmagick::chopimage() function is an inbuilt function in PHP which is used to remove the region of an image and trim it. This function accepts the dimension of image and chops the area and the dimension from where the image is to be trim.Syntax: Gmagick Gmagick::chopimage( $width, $height, $x, $y
    2 min read
  • PHP | Imagick flopImage() Function
    The Imagick::flopImage() function is an inbuilt function in PHP which is used to create a horizontal mirror image. Syntax: bool Imagick::flopImage( void ) Parameters: This function does not accept any parameter. Return Value: This function returns True on success. Below programs illustrate the Imagi
    1 min read
  • PHP | Imagick clampImage() Function
    The Imagick::clampImage() function is an inbuilt function in PHP which is used to restricts the color range from 0 to the quantum depth. This function has no impact on the image which is already in given range. Syntax: bool Imagick::clampImage( int $channel = Imagick::CHANNEL_DEFAULT ) Parameters: T
    1 min read
  • PHP | Imagick charcoalImage() Function
    The Imagick::charcoalImage() function is an inbuilt function in PHP which is used to simulate a charcoal drawing of an image. Syntax: bool Imagick::charcoalImage( $radius, $sigma ) Parameters: This function accepts two parameters as mentioned above and described below: $radius: This parameter stores
    1 min read
  • PHP | Imagick drawImage() Function
    The Imagick::drawImage() function is an inbuilt function in PHP which is used to render the ImagickDraw object on the Imagick object. It is used to draw the image on the Imagick instance. We set an image matrix, parameters and the borders of the drawn image with the help of ImagickDraw methods and t
    2 min read
  • PHP | Imagick blurImage() function
    The Imagick::blurImage() function is an inbuilt function in PHP which is used to add blur filter to the image. This function returns True on success. Syntax: bool Imagick::blurImage( $radius, $sigma, $channel ) Parameters: This function accepts three parameters as mentioned above and described below
    1 min read
  • PHP | Imagick flipImage() Function
    The Imagick::flipImage() function is an inbuilt function in PHP which is used to create an image generated by a mirror-reversal of an original image across a vertical mirror. Syntax: bool Imagick::flipImage( void ) Parameters: This function does not accepts any parameters. Return Value: This functio
    1 min read
  • PHP | Imagick clutImage() Function
    The Imagick::clutImage() function is an inbuilt function in PHP which is used to replace the colors in the image. The second parameter of this function replaces the color in a specific channel. Syntax: bool Imagick::clutImage( $lookup_table, $channel = Imagick::CHANNEL_DEFAULT ) Parameters: This fun
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences