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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:29:16+00:00 2026-06-06T01:29:16+00:00

I have an image on my filesystem. I display it on a page with

  • 0

I have an image on my filesystem. I display it on a page with a cropping tool, but I size it down to fit into the cropping tool area (or stretch it to take up the whole area if the image is smaller than the area). On this page the user would select a region of the photo to keep (using jcrop) and submit.

On the backend I will be waiting for the coordinates from the previous page. I will get x1, x2, y1, y2, w, and h.

The problem is that the coordinates on the resized image (the one displayed to the user) are not readily usable on the full sized image as they will either account for a region smaller than the image (it was sized down to fit on the screen) or it will be larger than the image (it was stretched to fit on the screen).

I can get the height and width of the original photo as well as the static width and height it was forced into.

How would you find the correct region of the image given the known dimensions?

My current code is here

$target_width = 150;
$target_height = 150;
$jpeg_quality= 90;
$tmp =explode('/',$_POST['filename']); 

$src = '../uploads/'.$tmp[count($tmp)-1];

$x1 = $_POST['x1'];
$x2 = $_POST['x2'];
$y1 = $_POST['y1'];
$y2 = $_POST['y2'];
$w = $_POST['w'];
$h = $_POST['h'];

$image = imagecreatefromjpeg($src);
$final = imagecreatetruecolor($target_width, $target_height);

imagecopyresampled($final, $image, 0, 0, $x1, $y1, $target_width, $target_height, $w, $h);
imagejpeg($final, $src, $jpeg_quality);
  • 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-06T01:29:16+00:00Added an answer on June 6, 2026 at 1:29 am

    Maybe my question wasn’t very clear (I had trouble explaining to someone IRL as well) but my answer should clear it up pretty well.

    I have an image on my filesystem (path is available to me at $_POST[‘image_path’]) and an image tag that looks like “”. I got the data from the image tag with some jquery magic.

    ‘Proportions’ is the answer.
    The h_limit is the height constraint of the img tag
    The w_limit is the width constraint of the img tag

    $h_limit = $_POST['h_limit'];
    $w_limit = $_POST['w_limit'];
    
    list($width, $height) = getimagesize($_POST['image_path']);
    $w_mult = $width/$w_limit;
    $h_mult = $height/$h_limit;
    

    And then I could just do

    imagecopyresampled($final, $image, 0, 0, $x1*$w_mult, $y1*$h_mult, $target_width, $target_height, $w*$w_mult, $h*$h_mult);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have image map that can I move, but this map will be so
I have image and txt file of same size say 200 KB. Now i
I have recently started looking into using Azure but I'm having some issues getting
I have used the following code before uploading an image into mysql database Before
I have a UIWebView and I want to load an SVG image into it.
I have image Array with two images out of that first image its showing
I have image on server of dimension 1000x800. I download it using following approaches:
I have image upload, where I check, how big part of image is already
I have image A and image B. They are located in the different places
i have a div that it have image content .i wanna implement animation when

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.