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 8673737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:32:07+00:00 2026-06-12T19:32:07+00:00

Spending time reading through the docs, and searching for examples. I understand cropping an

  • 0

Spending time reading through the docs, and searching for examples. I understand cropping an image from top 0, and left 0 is pretty straight forward. However. I would like to pass 2 sets of coordinates, a starting point and an ending point. Four Points, a Square that is defined anywhere. However from the examples I am finding, and from what I gather the rendition is not going to let me do this. codeigniter so I am seeking confirmation on this thought, is it true that I can only provide end points from 0, and it crops a square based on said end points or can I actually specify an x start, an x end, and similar for y?

Or is there some other technique I can use within codeigniter that will allow me to pass for coordinates for starting and ending points?

  • 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-06-12T19:32:09+00:00Added an answer on June 12, 2026 at 7:32 pm

    You can use for example of class of defined cropping image and call it a class via library or helper in a codeigniter:

    For example call it:

    LibraryCropImage::ResizedThumbnail($profile_thumbsize_x, $profile_thumbsize_x, $path, $filename, $path_to, $filename_to.'_sized', $quality, $fileextension);
    LibraryCropImage::CroppedThumbnail($profile_thumbsize_x, $profile_thumbsize_x, $path, $filename, $path_to, $filename_to.'_cropped', $quality, $fileextension);
    
    abstract class LibraryCropImage  {
    
        function ResizedThumbnail($thumbnail_width, $thumbnail_height, $path, $filename, $path_to, $filename_to, $quality, $ext)
        {
        list($width, $height) = getimagesize($path.$filename);
    
        $new_width = $thumbnail_width;
        $new_height = $thumbnail_height;
    
        if ($ext == "jpg" || $ext == "jpeg")
        {
            $thumb = @imagecreatefromjpeg($path.$filename);
        }
        else if ($ext == "gif")
        {
            $thumb = @imagecreatefromgif($path.$filename);
        }
        else if ($ext == "png")
        {
            $thumb = @imagecreatefrompng($path.$filename);
        }
        $thumbp = imagecreatetruecolor($new_width, $new_height);
    
    
    
        imagecopyresampled($thumbp, $thumb, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    
        ob_start();
        if ($ext == "jpg" || $ext == "jpeg")
        {
            imagejpeg($thumbp, null, $quality);
        }
        else if ($ext == "gif")
        {
            imagegif($thumbp);
        }
        else if ($ext == "png")
        {
            imagepng($thumbp, null);
        }
        $i = ob_get_clean();
        $fp = fopen($path_to.$filename_to.'.'.$ext, 'w');
        fwrite ($fp, $i);
        fclose ($fp);
        imagedestroy($thumbp);
        }
    
        function CroppedThumbnail($thumbnail_width, $thumbnail_height, $path, $filename, $path_to, $filename_to, $quality, $ext)
        {
        list($width, $height) = getimagesize($path.$filename);
    
        $new_width = $thumbnail_width;
        $new_height = $thumbnail_height;
    
        if ($ext == "jpg" || $ext == "jpeg")
        {
            $image = @imagecreatefromjpeg($path.$filename);
        }
        else if ($ext == "gif")
        {
            $image = @imagecreatefromgif($path.$filename);
        }
        else if ($ext == "png")
        {
            $image = @imagecreatefrompng($path.$filename);
        }
    
        $filename = $path.$filename;
    
        $thumb_width = $thumbnail_width;
        $thumb_height = $thumbnail_height;
    
        $width = imagesx($image);
        $height = imagesy($image);
    
        $original_aspect = $width / $height;
        $thumb_aspect = $thumb_width / $thumb_height;
    
        if($original_aspect >= $thumb_aspect) {
           // If image is wider than thumbnail (in aspect ratio sense)
           $new_height = $thumb_height;
           $new_width = $width / ($height / $thumb_height);
        } else {
           // If the thumbnail is wider than the image
           $new_width = $thumb_width;
           $new_height = $height / ($width / $thumb_width);
        }
    
        $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
    
        // Resize and crop 
        imagecopyresampled($thumb,
                           $image,
                           0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
                           0 - ($new_height - $thumb_height) / 2, // Center the image vertically
                           0, 0,
                           $new_width, $new_height,
                           $width, $height);
    
    
        ob_start();
        if ($ext == "jpg" || $ext == "jpeg")
        {
            imagejpeg($thumb, null, $quality);
        }
        else if ($ext == "gif")
        {
            imagegif($thumb);
        }
        else if ($ext == "png")
        {
            imagepng($thumb, null);
        }
        $i = ob_get_clean();
        $fp = fopen($path_to.$filename_to.'.'.$ext, 'w');
        fwrite ($fp, $i);
        fclose ($fp);
        imagedestroy($thumb);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been spending a lot of time reading online presentations and textbooks about the
Before spending any time reading this, see the self-answer below. The problem was invalid
What Is the exact use of DSL? Is it worth time spending on reading
I am still very new to Ruby (reading through the Pickaxe and spending most
I am new to DirectX, and after spending some time in reading the documentation
After spending some time wireframing my ideas, I want to start building my rails
I've been spending some time doing JavaCC parser generation for assignments at University and
I have been spending some time on this. My problem involves bringing back domain
I'm trying to refresh a page without sending POST from the previous time. I've
My hardware has a problem, from time to time it's sending a keydown followed

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.