 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
05-15-2008, 04:00 PM
|
#1 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
cropping images ( this style ) [REQUEST]
how do I do this:
http://garrysmod.com/challenge/image...30&w=125&h=250
I made a crop image which centers itself from the corridinates by cropped images, and dividing by 2 but.. how do I achieve this effect, by the way, go ahead and increase the w and h url vars to see more.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-16-2008, 02:35 AM
|
#2 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
[bump] 12346 vvvv
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-17-2008, 05:55 AM
|
#3 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
I did a quick thumbnail function here to show you how simple it really is, it might not be working as im pretty tired and I was about to go to bed ;)
PHP Code:
<?php
/** Assuming $source is an image resource to the image we need to alter */
/** Max width + height */
$width = 100;
$height = 100;
$factor = 1;
if(imagesx($source) > $width)
{
$factor = ($width / imagesx($source));
}
if((imagesy($source) * $factor) > $height)
{
$factor = ($height / imagesy($source));
}
$width = floor(imagesx($source) * $factor);
$height = floor(imagesy($source) * $factor);
$thumbnail = imagecreatetruecolor($width, $height);
$bg = imagecolorallocate($thumbnail, 255, 255, 255);
imagefilledrectangle($thumbnail, 0, 0, (imagesx($thumbnail) - 1), (imagesy($thumbnail) - 1), $bg);
imagecopyresampled($thumbnail, $source, 0, 0, 0, 0, $width, $height, imagesx($source), imagesy($source));
imagedestroy($source);
$source = NULL;
/** $thumbnail is now the generated thumbnail */
?>
__________________
Last edited by Kalle : 05-19-2008 at 12:49 AM.
|
|
|
|
The Following User Says Thank You to Kalle For This Useful Post:
|
|
05-18-2008, 10:26 PM
|
#4 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Kalle
I did a quick thumbnail function here to show you how simple it really is, it might not be working as im pretty tired and I was about to go to bed ;)
PHP Code:
<?php
/** Assuming $source is an image resource to the image we need to alter */
/** Max width + height */
$width = 100;
$height = 100;
$factor = 1;
if(imagesx($source) > $width)
{
$factor = ($width / imagesx($source));
}
if((imagesy($source * $factor) > $height)
{
$factor = ($height / imagesy($source));
}
$width = floor(imagesx($source) * $factor);
$height = floor(imagesy($source) * $factor);
$thumbnail = imagecreatefromtruecolor($width, $height);
$bg = imagecolorallocate($thumbnail, 255, 255, 255);
imagefilledrectangle($thumbnail, 0, 0, (imagesx($thumbnail) - 1), (imagesy($thumbnail) - 1), $bg);
imagecopyresampled($thumbnail, $source, 0, 0, 0, 0, $width, $height, imagesx($source), imagesy($source));
imagedestroy($source);
$source = NULL;
/** $thumbnail is now the generated thumbnail */
?>
|
Didn't work at all :P
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-19-2008, 12:47 AM
|
#5 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
Hmm I fixed the code, but I see it wasn't what you wanted in first place, but thats what you get out of being up late >.<
__________________
|
|
|
05-19-2008, 06:29 AM
|
#6 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by Kalle
Hmm I fixed the code, but I see it wasn't what you wanted in first place, but thats what you get out of being up late >.<
|
xD, it's alright. I'll figure it out some how.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-19-2008, 08:35 AM
|
#7 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
PHP: imagecopyresized - Manual
Will do what you want, look specifically at SRC_X and SRC_Y -- you can tell it what coordinates you want to start the copy at, effectively creating a cropped area.
-m
|
|
|
|
05-19-2008, 08:37 AM
|
#8 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by delayedinsanity
PHP: imagecopyresized - Manual
Will do what you want, look specifically at SRC_X and SRC_Y -- you can tell it what coordinates you want to start the copy at, effectively creating a cropped area.
-m
|
I use resampled
:P
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-21-2008, 03:33 PM
|
#9 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
[quote=delayedinsanity;14731] PHP: imagecopyresized - Manual
Will do what you want, look specifically at SRC_X and SRC_Y -- you can tell it what coordinates you want to start the copy at, effectively creating a cropped area.
-m[/QUoute]
************************************************** ********
One quick question. I'm trying to do the same thing. I'd like to start my cropping from a particular area/coordinates.
Below is the sample code. Also, if you follow the link to the original gif and then in your favorite editor crop the image so that its at the following dimension 438x519 from the center. I took the following pixels (left 0, Right 119, Top 476, Bottom 204). This above result is what I'm trying to get the following code to produce.
Any assistance again you may provide would truly be appreciated.
Thank you,
j4v1
PHP Code:
<?php
cropImage(500, 460, 'http://images.wsdot.wa.gov/nwflow/flowmaps/sysvert.gif', 'gif', 'test500x460.gif');
function cropImage($nw, $nh, $source, $stype, $dest) {
$size = getimagesize($source);
$w = $size[0];
$h = $size[1];
switch($stype) {
case 'gif':
$simg = imagecreatefromgif($source);
break;
case 'jpg':
$simg = imagecreatefromjpeg($source);
break;
case 'png':
$simg = imagecreatefrompng($source);
break;
}
$dimg = imagecreatetruecolor($nw, $nh);
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/2;
if($w > $h) {
$adjusted_width = $w / $hm;
$half_width = $adjusted_width / 2;
$int_width = $half_width - $w_height;
imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
} elseif(($w < $h) || ($w == $h)) {
$adjusted_height = $h / $wm;
$half_height = $adjusted_height / 2;
$int_height = $half_height - $h_height;
imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
} else {
imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
}
imagejpeg($dimg,$dest,100);
}
?>
|
|
|
|
05-19-2008, 04:37 PM
|
#10 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Okay, but it can still do it, and in this case if all you want to do is create a cropped area you don't need to use resampled, because you're not resizing. You're just chopping some off.
-m
edit: I just looked closer at your example. It's not cropping like I originally thought, it's just resizing. So that should be easy? Let me try something here...
|
|
|
|
05-19-2008, 04:59 PM
|
#11 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Okay, so theirs isn't just resizing, it's cropping too, based on what size you enter... so this is pretty close, all mine does is resize it, but I just woke up. I think they're probably using some kind of math to figure out a crop area based on the ratio of the size entered. I didn't tinker with that at all. Also i'm not sure if you can dynamically display the new image without saving it as an actual physical file somewhere. If you can, I'd love to know how, if anybody knows?
PHP Code:
<?php function thumbnail ($szFile, $intNewWidth, $intNewHeight) {
$aImg = getimagesize($szFile); $intWidth = $aImg[0]; $intHeight = $aImg[1]; $szFileType = $aImg['mime']; unset($aImg);
switch ($szFileType) { case "image/pjpeg": case "image/jpeg": $imgNew = imagecreatefromjpeg($szFile); break; case "image/x-png": case "image/png": $imgNew = imagecreatefrompng($szFile); break; case "image/gif": $imgNew = imagecreatefromgif($szFile); break; default: return false; }
$imgResized = imagecreatetruecolor($intNewWidth, $intNewHeight); imagecopyresampled($imgResized, $imgNew, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight); if (imagejpeg($imgResized, "temp/temp.jpg", 100)) { imagedestroy($imgResized); imagedestroy($imgNew); return true; } else { imagedestroy($imgResized); imagedestroy($imgNew); return false; }
} // thumbnail()
$file = "path/to/your.jpg"; thumbnail($file, $_GET['w'], $_GET['h']); ?>
<img src="temp/temp.jpg" />
-m
|
|
|
|
05-19-2008, 09:38 PM
|
#12 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by delayedinsanity
Okay, so theirs isn't just resizing, it's cropping too, based on what size you enter... so this is pretty close, all mine does is resize it, but I just woke up. I think they're probably using some kind of math to figure out a crop area based on the ratio of the size entered. I didn't tinker with that at all. Also i'm not sure if you can dynamically display the new image without saving it as an actual physical file somewhere. If you can, I'd love to know how, if anybody knows?
PHP Code:
<?php
function thumbnail ($szFile, $intNewWidth, $intNewHeight) {
$aImg = getimagesize($szFile);
$intWidth = $aImg[0];
$intHeight = $aImg[1];
$szFileType = $aImg['mime'];
unset($aImg);
switch ($szFileType) {
case "image/pjpeg": case "image/jpeg": $imgNew = imagecreatefromjpeg($szFile); break;
case "image/x-png": case "image/png": $imgNew = imagecreatefrompng($szFile); break;
case "image/gif": $imgNew = imagecreatefromgif($szFile); break;
default: return false;
}
$imgResized = imagecreatetruecolor($intNewWidth, $intNewHeight);
imagecopyresampled($imgResized, $imgNew, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight);
if (imagejpeg($imgResized, "temp/temp.jpg", 100)) {
imagedestroy($imgResized);
imagedestroy($imgNew);
return true;
} else {
imagedestroy($imgResized);
imagedestroy($imgNew);
return false;
}
} // thumbnail()
$file = "path/to/your.jpg";
thumbnail($file, $_GET['w'], $_GET['h']);
?>
<img src="temp/temp.jpg" />
-m
|
I have no idea, I know the person who made the site though, all he told me was he kept the aspect ratio the same, though I did that, and it still looks like shit. :P his is better. and he said to do it, was just math. -_- ugh.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-19-2008, 10:29 PM
|
#13 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
If you know the person, tell him to cough up the code so you can dissect it and learn!
-m
|
|
|
|
05-19-2008, 10:31 PM
|
#14 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by delayedinsanity
If you know the person, tell him to cough up the code so you can dissect it and learn!
-m
|
Well alright, but hes not one to really give up his code. ;P
He has his own forums:
Facepunch Studios (Forums)
though I warn you, theres idiots about xD
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|