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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:34:45+00:00 2026-05-30T09:34:45+00:00

I’m trying to create thumbnail and resize image at the same time, so to

  • 0

I’m trying to create thumbnail and resize image at the same time, so to be more clear here is the image that i’m trying to crop:

enter image description here

And i would like to cut out that red area.

Now my problem is that i’m resizing my image with html before croping so when i submit data to php i get incorrect values, like y = 100 when realy it could be y = 200 so i need to find a way to calculate my values.

I am using imagecopyresampled, maybe there is something better then this command?

Also my closest soliution was this:

imagecopyresampled(
    $thumb, //Destination image link resource.
    $src,   //Source image link resource.
    0,      //x-coordinate of destination point.
    0,      //y-coordinate of destination point.
    0,      //x-coordinate of source point.
    0,      //y-coordinate of source point.
    120,    //Destination width.
    160,    //Destination height.
    $image_width/2, //Source width.
    $image_height/2  //Source height.
);

In this case it would cut out left corner but size would be not the same as my red box.
So i guess i need to get source width and source height right and everything else should fit perfectly, anyways i hope i make any sense here 🙂

EDIT Sorry i forgot to mention, $image_width and $image_height is the original image size

EDIT 2 To be more clear this is what i get when i resize with this code

$dimensions = getimagesize('testas.jpg');

$img = imagecreatetruecolor(120, 160); 
$src = imagecreatefromjpeg('testas.jpg');

imagecopyresampled($img, $src, 0, 0, 0, 0, 120, 160, $dimensions[0]/2, $dimensions[1]/2); 

imagejpeg($img, 'test.jpg');

enter image description here

Resized image size is correct, but as you can it doesn’t look right.

  • 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-30T09:34:46+00:00Added an answer on May 30, 2026 at 9:34 am

    I use something like this to scale images:

    public static function scaleProportional($img_w,$img_h,$max=50)
    {
        $w = 0;
        $h = 0;
    
        $img_w > $img_h ? $w = $img_w / $img_h : $w = 1;
        $img_h > $img_w ? $h = $img_h / $img_w : $h = 1;
    
        $ws = $w > $h ? $ws = ($w / $w) * $max : $ws = (1 / $h) * $max;
        $hs = $h > $w ? $hs = ($h / $h) * $max : $hs = (1 / $w) * $max;
    
        return array(
            'width'=>$ws,
            'height'=>$hs
        );
    }
    

    usage:

                $getScale = Common::scaleProportional($prevWidth,$prevHeight,$scaleArray[$i][1]);
                $targ_w = $getScale['width'];
                $targ_h = $getScale['height'];
                $jpeg_quality = 100;
    
                $src = $prevdest;
    
                $img_r = imagecreatefromjpeg($src);
                $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
                //imagecopyresampled(dest_img,src_img,dst_x,dst_y,src_x,src_y,dst_w,dst_h,src_w,src_h);
                imagecopyresampled($dst_r,$img_r,0,0,0,0,$targ_w,$targ_h,$prevWidth,$prevHeight);
                imagejpeg($dst_r, 'assets/images/'.$scaleArray[$i][0].'/'.$filename, $jpeg_quality);
                $complete[] = $scaleArray[$i][0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to understand how to use SyndicationItem to display feed which is

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.