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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:36:26+00:00 2026-06-02T23:36:26+00:00

I have this piece of code here imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height); Baiscally what I am trying to

  • 0

I have this piece of code here

imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height);

Baiscally what I am trying to do is upload an image and resize the width and have the height adjusted based on the width.

I tried this also

imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width);

without the height and got this error

Warning: Wrong parameter count for imagecopyresampled() in /home/content/44/8713044/html/admin/Categories.php on line 63

this is the current code where the $width and $height variables come from.

if($width> $height) {
            $x = ceil(($width - $height) / 2 );
            $width = $height;
        } elseif($height> $width) {
            $y = ceil(($height - $width) / 2);
            $height = $width;
        }

Any Help would be appreciated, Thanks in advanced,
J

Here is the full function..

function create_thumbnail($source,$destination, $thumb_width) {
        $percent = 0.5;
        $size = getimagesize($source);
        $width = $size[0];
        $height = $size[1];
        $x = 0;
        $y = 0;
        if($width> $height) {
            $x = ceil(($width - $height) / 2 );
            $width = $height;
        } elseif($height> $width) {
            $y = ceil(($height - $width) / 2);
            $height = $width;
        }
        $new_image = imagecreatetruecolor($thumb_width,$thumb_width)or die('Cannot Initialize new GD image stream');
        $extension = get_image_extension($source);
         if($extension=='jpg' || $extension=='jpeg') 
            $image = imagecreatefromjpeg($source); 
        if($extension=='gif') 
            $image = imagecreatefromgif($source); 
        if($extension=='png') 
            $image = imagecreatefrompng($source);   

        imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width,$thumb_width,$width,$height);
        if($extension=='jpg' || $extension=='jpeg') 
           imagejpeg($new_image,$destination); 
        if($extension=='gif') 
            imagegif($new_image,$destination); 
        if($extension=='png') 
            imagepng($new_image,$destination); 
    }

the $thumb_width is 600 and this returns my image 600*600

  • 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-02T23:36:27+00:00Added an answer on June 2, 2026 at 11:36 pm

    This worked perfectly when i tested it …. Except you want to work with fixed size

    $filename = "a.jpg" ;
    $percent = 0.5;
    header('Content-Type: image/jpeg');
    list($width, $height) = getimagesize($filename);
    $new_width = $width * $percent;
    $new_height = $height * $percent;
    
    // Resample
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    imagejpeg($image_p, null, 100);
    

    Demo

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

Sidebar

Related Questions

Hey ya'll I have this piece of code here and what I am trying
I have this piece of Open MP code here which performs an integeration of
I have this piece of code: <table style=background-image: url(path/to_image.png)> And when I load it
I have this piece of code here below: $fq.= + (fritidsboende_uth_from:[$fritids_uth_from TO *] AND
I have this piece of code where I'm trying to convert the below C#
I'm making a Grade log application and I have this piece of code here
I have this piece of code right here , I really don't get it
I have written this piece of code here and I have linked it alright
here's my problem. I have this piece of code that sets the user location
I have this piece of code: div#permalink_section { width: 960px } <div id='permalink_section'> <a

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.