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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:55:32+00:00 2026-05-25T14:55:32+00:00

I’m using jQuery’s imgAreaSelect plugin in order to crop an image and save the

  • 0

I’m using jQuery’s imgAreaSelect plugin in order to crop an image and save the thumbnail to use in cases where, for example, the ratio changes. Unfortunelly the results are far from what I would expect, and I can’t get it right. The image gets resized as a whole instead of being cropped.

Here’s the test example :

<?php

/***
*
* $_GET returned values
*
* x1 = 0
* x2 = 400
* y1 = 66
* y2 = 258
* w = 400
* h = 192
* folder = widethumb
* filename = IMG_4591.jpg
* scale = 48
*
* Original image properties
*
* width = 600px
* height = 900px
*
***/

define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);

extract($_GET);

$fn = $filename;
$filename = DOCROOT.$filename;

list($width, $height) = getimagesize($filename);

$src = imagecreatefromjpeg($filename);
$dst = imagecreatetruecolor($w, $h);
imagecopyresampled($dst, $src, 0, 0, (int) $x1, (int) $y1, (int) $w, (int) $h, $width, $height);

header('Content-Type: image/jpeg');
imagejpeg($dst);

What am I mising here?

Cheers!

  • 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-25T14:55:33+00:00Added an answer on May 25, 2026 at 2:55 pm

    From PHP Documentation:

    bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
    

    imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.

    In other words, imagecopyresampled() will take an rectangular area from src_image of width src_w and height src_h at position (src_x,src_y) and place it in a rectangular area of dst_image of width dst_w and height dst_h at position (dst_x,dst_y).

    So to get the result you are looking for, you need to avoid scaling. for that use:

    imagecopy($dst, $src, 0, 0, $x1, $y1, $w, $h);
    
    // this can also be done but is less efficient (over 10 times slower)
    imagecopyresampled($dst, $src, 0, 0, (int) $x1, (int) $y1, $w, $h, $w, $h);
    

    Here we are are taking the same sized rectangle from source as we are putting it into destination image.
    I have just tested it and it works just fine.

    Update:
    I have just tried again on my test server and it is working fine. I’m using following code:

    $filename = "test.jpg";
    
    extract($_GET);
    
    $src = imagecreatefromjpeg($filename);
    $dst = imagecreatetruecolor($w, $h);
    imagecopy($dst, $src, 0, 0, $x1, $y1, $w, $h);
    
    // this is over 10 times slower, as we are only cropping we should use imagecopy
    //imagecopyresampled($dst, $src, 0, 0, $x1, $y1, $w, $h, $w, $h);
    
    header('Content-Type: image/jpeg');
    imagejpeg($dst);
    

    And I’m calling it like this:

    http://localserver/test/gd_crop.php?x1=906&y1=267&w=501&h=355

    Performance Update
    As we are not resizing we can simply use imagecopy. Performance of 3 functions as i have measured is given below.

    imagecopyresampled    69ms
    imagecopyresized      5.5ms
    imagecopy             4.5ms
    

    So there is an order of 10 speed difference between resampled and the two other functions.

    I have finally come up with following line in place of imagecopyresampled function, try it, I have also updated the above code listing:

    imagecopy($dst, $src, 0, 0, $x1, $y1, $w, $h);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported

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.