Image Resizer Help

Started on the old forum in November 2007 · view the original in the archive · old links redirect here

11 replies · 1,525 views · started 19 years ago · 1 min read

6 participants
rukiya Lead · 569 posts #1

this is the image resizer for .jpg files only,can any1 edit it,which will work for .gifand .png files also?CODE<?php // The file $filename = 'test.jpg';

// Set a maximum height and width $width = 200; $height = 200;

// Content type header('Content-type: image/jpeg');

// Get new dimensions list($width_orig, $height_orig) = getimagesize($filename);

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; }

// Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output imagejpeg($image_p, null, 100); ?>

amylee Principal · 1,092 posts #2

i presume you can by just adding few more Content-type: image/gif or Content-type: image/png yadda yadda thingys and add summat like imagegif($image_p, null, 100) or something at the end

rukiya Lead · 569 posts #3

i presume you can by just adding few more Content-type: image/gif or Content-type: image/png yadda yadda thingys and add summat like imagegif($image_p, null, 100) or something at the end

External image (may be gone) u hv forgotten to mention this variable $image = imagecreatefromjpeg($filename);

anyway i hv tried ur mentioned way but PHP didnt listen my edited codes,thats why i had to open this topic

subzero Super moderator Fellow · 3,954 posts #4
[url=" IMAGE URL "][img] IMAGE URL [/img][/url]

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

subzero Super moderator Fellow · 3,954 posts #6

there no way yet bro if ya wait ill make a images ok

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

rukiya Lead · 569 posts #7

there no way yet bro if ya wait ill make a images ok here is a code,but i cant combine the both codesCODE<?php

$taille = getimagesize("$pic"); $h_i = $taille[1]; $w_i = $taille[0]; if($h_i >$h_max) { $convert=$h_max/$h_i; $h_i=$h_max; $w_i=ceil($w_i*$convert); } if($w_i >$w_max) { $convert=$w_max/$w_i; $w_i=$w_max; $h_i=ceil($h_i*$convert); };

$largeur = "$w_i"; $hauteur ="$h_i";

header("Content-Type: image/jpeg"); list($width, $height, $type, $attr) = getimagesize("$pic");

if($type == "1") { $img_in = imagecreatefromgif($pic); }

if($type == "2") { $img_in = imagecreatefromjpeg($pic); }

if($type == "3") { $img_in = imagecreatefrompng($pic); }

$img_out = imagecreatetruecolor($largeur, $hauteur); imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in)); imagejpeg($img_out, null, 100); ?>

subzero Super moderator Fellow · 3,954 posts #8
<?php
header ("Content-type: image/jpeg");
$img = $_GET['img'];
$percent = $_GET['percent'];
$constrain = $_GET['constrain'];
$w = $_GET['w'];
$h = $_GET['h'];
$x = @getimagesize($img);
$sw = $x[0];
$sh = $x[1];
if ($percent > 0) {
$percent = $percent * 0.01;
$w = $sw * $percent;
$h = $sh * $percent;
} else {
if (isset ($w) AND !isset ($h)) {
$h = (100 / ($sw / $w)) * .01;
$h = @round ($sh * $h);
} elseif (isset ($h) AND !isset ($w)) {
$w = (100 / ($sh / $h)) * .01;
$w = @round ($sw * $w);
} elseif (isset ($h) AND isset ($w) AND isset ($constrain)) {
$hx = (100 / ($sw / $w)) * .01;
$hx = @round ($sh * $hx);
$wx = (100 / ($sh / $h)) * .01;
$wx = @round ($sw * $wx);
if ($hx < $h) {
$h = (100 / ($sw / $w)) * .01;
$h = @round ($sh * $h);
}else{
$w = (100 / ($sh / $h)) * .01;
$w = @round ($sw * $w);
}
}
}
$im = @ImageCreateFromJPEG ($img)
$im = @ImageCreateFromPNG ($img) 
$im = @ImageCreateFromGIF ($img) 
$im = false;
if (!$im) {
readfile ($img);
}else{
$thumb = @ImageCreateTrueColor ($w, $h);
@ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh);
@ImageJPEG ($thumb);
}
?>

Now to show ?h=10&w=15&img=

Now im going to bed try it mite be lucky i did things for ya External image (may be gone)

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

ori Lead · 512 posts #10

$sql=mysql_fetch_array(mysql_query("SELECT id, scode, imgsrc FROM ibwf_gallery ORDER BY RAND() LIMIT 1")); echo "<img src="$sql[2]" alt="$sql[1]"/>";

thats jus an example

rukiya Lead · 569 posts #12
<?php
header ("Content-type: image/jpeg");
$img = $_GET['img'];
$percent = $_GET['percent'];
$constrain = $_GET['constrain'];
$w = $_GET['w'];
$h = $_GET['h'];
$x = @getimagesize($img);
$sw = $x[0];
$sh = $x[1];
if ($percent > 0) {
$percent = $percent * 0.01;
$w = $sw * $percent;
$h = $sh * $percent;
} else {
if (isset ($w) AND !isset ($h)) {
$h = (100 / ($sw / $w)) * .01;
$h = @round ($sh * $h);
} elseif (isset ($h) AND !isset ($w)) {
$w = (100 / ($sh / $h)) * .01;
$w = @round ($sw * $w);
} elseif (isset ($h) AND isset ($w) AND isset ($constrain)) {
$hx = (100 / ($sw / $w)) * .01;
$hx = @round ($sh * $hx);
$wx = (100 / ($sh / $h)) * .01;
$wx = @round ($sw * $wx);
if ($hx < $h) {
$h = (100 / ($sw / $w)) * .01;
$h = @round ($sh * $h);
}else{
$w = (100 / ($sh / $h)) * .01;
$w = @round ($sw * $w);
}
}
}
$im = @ImageCreateFromJPEG ($img)
$im = @ImageCreateFromPNG ($img) 
$im = @ImageCreateFromGIF ($img) 
$im = false;
if (!$im) {
readfile ($img);
}else{
$thumb = @ImageCreateTrueColor ($w, $h);
@ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh);
@ImageJPEG ($thumb);
}
?>

Now to show ?h=10&w=15&img= Now im going to bed try it mite be lucky i did things for ya External image (may be gone)

thanks but it wont work as the MIME TYPE is only for jpeg

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close