Jump to content

[SOLVED] GD resized image needs a filename


techtheatre

Recommended Posts

I am trying to resize some images that i upload to my webserver.  I found a great (well it looks great...i have not yet used it) script to do this with GD, but i can't see where to rename the output file.  This tutorial was found here:

http://www.phptoys.com/e107_plugins/content/content.php?content.46

 

<?php
function resizeImage($originalImage,$toWidth,$toHeight){
    
    // Get the original geometry and calculate scales
    list($width, $height) = getimagesize($originalImage);
    $xscale=$width/$toWidth;
    $yscale=$height/$toHeight;
    
    // Recalculate new size with default ratio
    if ($yscale>$xscale){
        $new_width = round($width * (1/$yscale));
        $new_height = round($height * (1/$yscale));
    }
    else {
        $new_width = round($width * (1/$xscale));
        $new_height = round($height * (1/$xscale));
    }

    // Resize the original image
    $imageResized = imagecreatetruecolor($new_width, $new_height);
    $imageTmp     = imagecreatefromjpeg ($originalImage);
    imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    return $imageResized;
}
?> 

 

basically i just need a function that will resize and keep the proper porportions.  my original image is named 1_fullsize.jpg and i want to create one called 1_thumb.jpg (and another called 1_normal.jpg).  Where do i go about putting the new filename/path into this script to save my file?

 

Also, i have been told that ImageMagick is really the way to go...but have not been able to find easy tutorials for it...any thoughts on where i can find an easy imagemagick function to handle this (i have searched google for

ImageMagick resize tutorial which is actually how i found this one using GD  :-\ )

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.