Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:45:29+00:00 2026-05-31T11:45:29+00:00

I am trying to remove transparent areas of an image with php using imagick.

  • 0

I am trying to remove transparent areas of an image with php using imagick.

Image Magick provides the trim method:
Imagick::trimImage

Remove edges that are the background color from the image. This method is available if Imagick has been compiled against ImageMagick version 6.2.9 or newer.

How do I set the color which Imagick may trim?

The following script sets the background color to grey.
However trim removes the blue background color as you can see below.

$im = new Imagick( "1.png" );
// Set background color to grey
$im->setImageBackgroundColor( new ImagickPixel( "rgb(213,213,213)" ) );
$im->trimImage( 0 );
$im->writeImage('2.png');

enter image description here

Is there any way to limit the trim colors?

imagick module version => 2.1.1-rc1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:45:30+00:00Added an answer on May 31, 2026 at 11:45 am

    Matt Gibsons Hint led me to the right solution:
    http://www.imagemagick.org/Usage/crop/#trim_color

    As Matt already explained the trim method takes the corner colors to trim
    the image.
    The given solution from the documentation is a workaround:
    They draw a border around the image before they call the trim method.

    $img = new Imagick("stripes.gif"); 
    // Set the color to trim:
    $img->borderImage("#FF0000", 1, 1); 
    $img->trimImage(0); 
    $img->setImagePage(0, 0, 0, 0);
    $img->writeImage("test.jpg");'
    

    Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to remove all white or transparent pixels from an image, leaving the
Trying to remove the full url that is being returned to imgurl: Usually returns
I am trying to remove a certain color from my image however it's not
I'm trying use make a div's background transparent using a mixture of CSS3 rgba()
I'm trying to remove any lines that begin with the character '>' in a
So, I'm trying to fade in a transparent div, kinda like hulu does when
I'm currently trying to implement a editable details view using a grouped UITableView. I'd
I have a gloss method and I'm trying to get a inverted half moon
Trying to remove an appended div, I've tried .empty() and contents().remove(); I've commented out
Im trying to remove a single node from a doubly threaded linked list. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.