Jump to content

Image resize on upload


Errant_Shadow

Recommended Posts

Is there a simple way to just take an image submitted by a user and scale it to fit within maximum constraints that doesn't involve hundreds of lines and dozens of steps to install?

 

I need to take images from users, make sure they are no more than 432px wide, 288px high, and no more than 200 kb in size; and if they ARE, then I need to scale them to fit those constraints.

 

I'm working on a Linux server with PHP version 5.2.9

Link to comment
https://forums.phpfreaks.com/topic/168253-image-resize-on-upload/
Share on other sites

I thought my server had image magik. I'm weary of installing new things because I don't know enough about that to be confident in my skills and I don't have the money to pay my host to do it for me.

 

If there's no simple way to do this without installing something like that I'll probably end up doing that, but I wanted to make sure before I committed to the task.

you could always resize them and just use html to resize them. for example

 

<?php
  $picture = getimagesize("images/fullsized/{$row['picture']}");
$ox = $picture[0];
$oy = $picture[1];
if($ox > 0){
$ny = floor($oy * (180 / $ox));}

 

then your html

<?php
echo "<img src='images/fullsized/{$row['picture']}' width='180' height='{$ny}' />";

 

and then put in a div and then set a max-height: 288px; then overflow: hidden; to hid the excess. Or do any number of if statements for calculating the width and heights to get what you want. This way you don't have to have a bunch of small copies of the same picture

I was just using php to resize them on the page, but my employer wants to give the users the ability to upload their images directly to our server so now I have to worry about filling up our server with the ridiculously large images that users submit. These people are technological idiots, so I can't exactly tell them to just pop in to photoshop and scale it down. The whole reason I'm having to do this is because telling them to go to photobucket and link me their pics is just too much work for them.

 

So what I need to do it take whatever image they send and scale it down to a maximum dimension and size before saving it to the server.

Okay, looks like I have ImageMagik on my server but I can't figure out how to USE the damn thing :facewall: Just trying to run a simple test to make sure it's active...

 

<?php

$image = new Imagick('files/dragon-cloud.jpg');

echo '<img src="' . $image . '" /><hr>';

$image->thumbnailImage(100, 0);

echo '<hr><img src="' . $image . '" />';

?>

 

Fatal error: Class 'Imagick' not found in ../_temp/upload/scale.php on line 3

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.