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

  • Home
  • SEARCH
  • 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 8479727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:06:45+00:00 2026-06-10T19:06:45+00:00

I using following method to resize image: private function newDim($maxHeight, $maxWidth, $height, $width) {

  • 0

I using following method to resize image:

 private function newDim($maxHeight, $maxWidth, $height, $width) {

        if(($width / $height) >= ($maxWidth / $maxHeight)){
                $nw = $maxWidth;
                $nh = $height * ($maxWidth / $width);
                $nx = round(abs($maxHeight - $nh) / 2);
                $ny = 0 ;
        }else {
            // by height
                $nw = $width*($maxHeight/$height);
                $nh = $maxHeight;
                $nx = 0;
                $ny = round(abs($maxWidth - $nw) / 2); ;
        }

        return array($nw,$nh,$nx,$ny);
    }

After that I want to save this image. For this case I using this method:

 public function upload($file_param_name) {
        $file_name = $_FILES[$file_param_name]['name'];
        $source_file_path = $_FILES[$file_param_name]['tmp_name'];
        $$this->ext = pathinfo($file_name, PATHINFO_EXTENSION);
        $ext = 'jpg';
        $this->ext = $ext;
        $ext =strtolower($ext);
        $new_file_name = $file_name."-".md5(uniqid(rand(), true));
        $this->image_hashname = $new_file_name;
        $target_path = $this->store_folder.basename($new_file_name);

        list($width,$height,$type)=getimagesize($source_file_path);

        switch ($type) {
            case 1:   //   gif -> jpg
                $src = imagecreatefromgif($source_file_path);
                break;
            case 2:   //   jpeg -> jpg
                $src = imagecreatefromjpeg($source_file_path);
                break;
            case 3:  //   png -> jpg
                $src = imagecreatefrompng($source_file_path);
                break;
        }

        $th = 240;
        $tw = 240;

        list($nh,$nw,$nx,$ny) = $this->newDim($th, $tw, $height, $width);

        $tmp=imagecreatetruecolor($tw,$th);

        $white = imagecolorallocate($tmp, 255,255,255);
        imagefill($tmp, 0, 0, $white);

        imagecopyresized($tmp,$src,$ny,$nx,0,0,$nh,$nw,$width,$height);
        $thmbfile = $this->store_folder.basename($new_file_name."-thumb.".$ext);
        imagejpeg($tmp,$thmbfile,100);


        imagedestroy($src);
        imagedestroy($tmp);
    }

When I save image with sizes 300×300 to 240×240 the quality of new image is very poor. Where I’m wrong?

The images :

OLD: http://cbn-design.eu/imgs/original.jpg

NEW: http://cbn-design.eu/imgs/new.jpg

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

    As per this answer, try using imagecopyresampled() instead of imagecopyresized().

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

Sidebar

Related Questions

I am using following method to get bitmap from url but image is not
I am using the following method to serialize a date as a string private
I'm using the following method to open my SQLite db. private void open() {
I'm using following method to highlight the keywords in a given text. private string
I have generated few elements in my page using following method. For example, $(#button+caption).click(function(){
I'm using the following code to resize an image so it fits inside a
I am using the following method to reverse geocode a google maps latlng: [GClientGeocoder.getLocations(address:String,
I am using the following method to basically create a JSON string. var saveData
I am using the following method to get the time of the video with
I'm using the following method in my code: - (NSMutableArray *) newOrderedArray:(NSMutableArray *)array ByKey:(NSString

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.