| | |
how can we minus 15 pixel from fitting image in this code ?
Thread Solved |
•
•
Join Date: Dec 2009
Posts: 29
Reputation:
Solved Threads: 0
hi
how can we minus 15 pixel from bottom height in fitting for create thumbnails from original image in this code ? i mean how can tell php that capture from original image the ( all width ) and ( all height - 15 pixel from bottom )
how can we minus 15 pixel from bottom height in fitting for create thumbnails from original image in this code ? i mean how can tell php that capture from original image the ( all width ) and ( all height - 15 pixel from bottom )
PHP Syntax (Toggle Plain Text)
# #create thumb # $thumb = gd_fit($image,$settings['thumbxy']); # function gd_fit(&$image, $target) { # # //takes the larger size of the width and height and applies the # //formula accordingly...this is so this script will work # //dynamically with any size image # # $width = gd_width($image); # $height = gd_height($image); # # if ($width > $height) { # $percentage = ($target / $width); # } else { # $percentage = ($target / $height); # } # # //gets the new value and applies the percentage, then rounds the value # $width = round($width * $percentage); # $height = round($height * $percentage); # # //returns the new sizes in html image tag format...this is so you # //can plug this function inside an image tag # # return gd_resize($image,$width,$height); # # }
0
#2 Dec 13th, 2009
Try this - I messed around with it for a while, but I'm sure it could be further optimized - perhaps with just the one imagecopyresampled - but my head's fried.
BTW - I left out any "constrain proportions" code.
PHP Syntax (Toggle Plain Text)
<?php function CutThumb($img){ //set variables $crop = 15; $thumb_w = 100; $thumb_h = 100; //get info from original image list($w, $h) = getimagesize($img); //make image a resource for use in functions $img_r = imagecreatefromjpeg($img); //make image containers for functions $cut = imagecreatetruecolor($w,$h-$crop); $thumb = imagecreatetruecolor($thumb_w,$thumb_h); //crop the original image imagecopyresampled($cut,$img_r,0,0,0,0,$w,$h,$w,$h-$crop); //resize the image imagecopyresampled($thumb,$cut,0,0,0,0,$thumb_w,$thumb_h,$w,$h-$crop); //release memory imagedestroy($img_r); imagedestroy($cut); //return image return $thumb; } //Create the thumbnail - this could be in any file if the function above is included $MyCutThumb = CutThumb("burton.jpg"); // Display image header('Content-type: image/jpeg'); imagejpeg($MyCutThumb); ?>
BTW - I left out any "constrain proportions" code.
Last edited by ardav; Dec 13th, 2009 at 6:27 pm.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
•
•
Join Date: Dec 2009
Posts: 29
Reputation:
Solved Threads: 0
0
#3 Dec 13th, 2009
hi dear ardav
Thanks for reply
but it would crop the original image , i just need it without affecting in the original image ?
i have the code above that my script working with it's using function gd_fit , it's fitting that image with variables , so can we try to edit this code to add $crop = 15 and minus it from height ? i don't know how to do it exactly
Thanks for reply
but it would crop the original image , i just need it without affecting in the original image ?
i have the code above that my script working with it's using function gd_fit , it's fitting that image with variables , so can we try to edit this code to add $crop = 15 and minus it from height ? i don't know how to do it exactly
0
#4 Dec 14th, 2009
Have to be honest - I don't really understand exactly what you want:
Do you just want to resize the image (height only)?
e.g. just take 15px off the height and don't worry about stretching the width
Do you just want to resize the height and keep the width in proportion?
e.g. take 15 px off the height of the image and scale the width accordingly
Do you need to crop the image? I assume not from your last post.
Do you just want to resize the image (height only)?
e.g. just take 15px off the height and don't worry about stretching the width
Do you just want to resize the height and keep the width in proportion?
e.g. take 15 px off the height of the image and scale the width accordingly
Do you need to crop the image? I assume not from your last post.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
•
•
Join Date: Dec 2009
Posts: 29
Reputation:
Solved Threads: 0
0
#5 Dec 14th, 2009
Thanks Dear ardav for reply
i just want to crop 15 pixel from the thumbnails only not the original image , why ? because all images i upload have my own watermark on the bottom this watermark size 15 pixel in the bottom , and i just want that watermark disappear in ( thumbnails only)
can i send you the script to take a look ?
i just want to crop 15 pixel from the thumbnails only not the original image , why ? because all images i upload have my own watermark on the bottom this watermark size 15 pixel in the bottom , and i just want that watermark disappear in ( thumbnails only)
can i send you the script to take a look ?
0
#6 Dec 14th, 2009
•
•
•
•
Thanks Dear ardav for reply
i just want to crop 15 pixel from the thumbnails only not the original image , why ? because all images i upload have my own watermark on the bottom this watermark size 15 pixel in the bottom , and i just want that watermark disappear in ( thumbnails only)
can i send you the script to take a look ?
What we need to know is the nature of your thumbnail - is it set as a %age of a width or height or is it set to a certain pixel height or width. AND is it "constrained" (scaled to proportion)?
Your solution will be similar to the one I suggested, except that the resizing is completed first and then the cropping (opposite to my suggestion).
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
•
•
Join Date: Dec 2009
Posts: 29
Reputation:
Solved Threads: 0
0
#7 Dec 14th, 2009
hi this is the script i'm using
http://rapidshare.com/files/320757609/im1_1.zip.html
i think that
creating thumbnail code in upload.php ( $thumb = gd_fit($image,$settings['thumbxy']); )
and functions located in includes folder , and gd_fit function that thumbnail using in dpi_ext.php
http://rapidshare.com/files/320757609/im1_1.zip.html
i think that
creating thumbnail code in upload.php ( $thumb = gd_fit($image,$settings['thumbxy']); )
and functions located in includes folder , and gd_fit function that thumbnail using in dpi_ext.php
•
•
Join Date: Dec 2009
Posts: 29
Reputation:
Solved Threads: 0
0
#9 Dec 14th, 2009
ok dear i will copy codes that i think involved with the issue
here that in uploud.php
functions that in dpi_ext.php (and think it's involved with the issue
other functions in dpi_ext.php
here that in uploud.php
PHP Syntax (Toggle Plain Text)
#create thumb $thumb = gd_fit($image,$settings['thumbxy']); #Accomodate image options if(isset($_REQUEST['border']) || isset($_POST['border'])) gd_rectangle($image,0,0,gd_width($image)-1,gd_height($image)-1,"000000"); if(isset($_REQUEST['bordert']) || isset($_POST['bordert'])) gd_rectangle($thumb,0,0,gd_width($thumb)-1,gd_height($thumb)-1,"000000"); #save thmb first imagejpeg($thumb,"$th/$id.jpg",$settings['thumbuality']); imagedestroy($thumb); #then save actual jpeg imagejpeg($image,"$im/$id.jpg",$settings['quality']); imagedestroy($image); $iptc = new iptc("$im/$id.jpg"); if($cimg[0] == 1) { #it is gif keep in data write_file("$im/$id.jpg",load_file("$th/$id.jpg")); write_file("$im/$id.gif",$cimg[1]); $iptc->set(DPI_GIF,"GIF"); }
functions that in dpi_ext.php (and think it's involved with the issue
PHP Syntax (Toggle Plain Text)
function gd_fit(&$image, $target) { //takes the larger size of the width and height and applies the //formula accordingly...this is so this script will work //dynamically with any size image $width = gd_width($image); $height = gd_height($image); if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format...this is so you //can plug this function inside an image tag and just get the return gd_resize($image,$width,$height); } function gd_getfit(&$image, $target) { //takes the larger size of the width and height and applies the //formula accordingly...this is so this script will work //dynamically with any size image $width = gd_width($image); $height = gd_height($image); if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format...this is so you //can plug this function inside an image tag and just get the return Array('width'=>$width,'height'=>$height); } function gd_width(&$image) { return imagesx($image); } function gd_height(&$image) { return imagesy($image); } function gd_imagewidth($fname) { list($width, $height) = getimagesize($fname); return $width; } function gd_imageheight($fname) { list($width, $height) = getimagesize($fname); return $height; } function gd_fit_bg(&$img,$fit=100,$color="FFFFFF") { $w = imageSX($img); $h = imageSY($img); $img2 = gd_newimage($fit,$fit); gd_bar($img2,0,0,$fit,$fit,$color); $x = ($fit-$w)/2; $y = ($fit-$h)/2; imagecopy($img2, $img, $x,$y, 0, 0, $w, $h); return $img2; } function gd_resize(&$image,$w,$h) { $ret=@imagecreatetruecolor($w, $h); @imagecopyresampled ($ret,$image, 0, 0, 0, 0, $w, $h, imagesx($image), imagesy($image)); return $ret; }
other functions in dpi_ext.php
PHP Syntax (Toggle Plain Text)
function dpi_supported($file) { $DPI_IMAGE_TYPES = Array(1,2,3,10); $size = @getimagesize($file); if(!$size) return false; return in_array($size[2],$DPI_IMAGE_TYPES) ? $size[2] : false; } function scanlines_h(&$image,$line_gap=1,$opacity=100) { $w = imagesx($image); $h = imagesy($image); $ret = imagecreatetruecolor($w,$h); $line_gap++; for ($y = 1; $y < $h; $y += $line_gap) imagecopymerge($ret, $image, 0, $y, 0, $y, $w, 1,$opacity); return $ret; } function scanlines_v(&$image,$line_gap=1,$opacity=100) { $w = imagesx($image); $h = imagesy($image); $ret = imagecreatetruecolor($w,$h); $line_gap++; for ($x = 1; $x < $w; $x += $line_gap) imagecopymerge($ret, $image, $x, 0, $x, 0, 1, $h,$opacity); return $ret; } function shear_r(&$image,$pers=50,$bgcolor="FFFFFF") { $w = imagesx($image); $h = imagesy($image); $ret = imagecreatetruecolor($w,$h); gd_bar($ret,0,0,$w,$h,$bgcolor); $z=0; $pers = 100-$pers; $pers /=100; $p1 = $h * $pers; $gap = $p1 / $w; for ($x = 0; $x < $w; $x++,$z+=$gap) imagecopyresampled ( $ret, #resource dst_im, $image, #resource src_im, $x, #int dstX, ($h-($h-$z))/2, #int dstY, $x, #int srcX, 0, #int srcY, 1, #int dstW, $h-$z, #int dstH, 1, #int srcW, $h #int srcH ); return $ret; } function shear_l(&$image,$pers=50,$bgcolor="FFFFFF") { $w = imagesx($image); $h = imagesy($image); $ret = imagecreatetruecolor($w,$h); gd_bar($ret,0,0,$w,$h,$bgcolor); $z=0; $pers = 100-$pers; $pers /=100; $p1 = $h * $pers; $gap = $p1 / $w; for ($x = $w-1; $x >= 0; $x--,$z+=$gap) imagecopyresampled ( $ret, #resource dst_im, $image, #resource src_im, $x, #int dstX, ($h-($h-$z))/2, #int dstY, $x, #int srcX, 0, #int srcY, 1, #int dstW, $h-$z, #int dstH, 1, #int srcW, $h #int srcH ); return $ret; } function load_dpi_image($name) { $name = str_replace(".jpg","",$name); @list($u,$d) = @explode("_",$name); $decdate = @hexdec($d); return @imagecreatefromstring(load_file(IMAGE_DIR.'/images/'.@date("Y/F/d",$decdate)."/$name.jpg")); } function gd_flip_h(&$image) { $ret = gd_newimage(imagesx($image),imagesy($image)); $w = imagesx($image); $h = imagesy($image); for ($x = 0; $x < $w; $x++) imagecopy($ret, $image, $w - $x - 1, 0, $x, 0, 1, $h); return $ret; } function gd_flip_v(&$image) { $ret = gd_newimage(imagesx($image),imagesy($image)); $w = imagesx($image); $h = imagesy($image); for ($x = 0; $x < $h; $x++) imagecopy($ret, $image, 0, $h - $x - 1, 0, $x, $w, 1); return $ret; } function gd_rotate(&$img,$ang=90,$col="FFFFFF") { $col = gd_hexgd($img,$col); return imagerotate($img,$ang,$col); } function gd_3db_watermark(&$img,$filepath) { $w = imageSX($img); $h = imageSY($img); $img2 = imagecreatefromstring(load_file($filepath)); $ww = imageSX($img2); $wh = imageSY($img2); $x = ($w-$ww)/2; $y = ($h-$wh)/2; imagecopy($img, $img2, $x, $y, 0, 0, $ww, $wh); return $img; } function gd_set_bg(&$img,$color="FFFFFF") { $w = imageSX($img); $h = imageSY($img); $img2 = gd_newimage($w,$h); gd_bar($img2,0,0,$w,$h,$color); imagecopy($img2, $img, 0, 0, 0, 0, $w, $h); return $img2; } function gd_hexgd(&$image,$hex) { $R = hexdec(@$hex{0}.@$hex{1}); $G = hexdec(@$hex{2}.@$hex{3}); $B = hexdec(@$hex{4}.@$hex{5}); return imagecolorallocate ($image, $R, $G, $B); } function gd_bar(&$image,$x=0,$y=0,$width,$height,$color="FFFFFF") { return imagefilledrectangle ($image, $x, $y, $x+$width, $y+$height, gd_hexgd($image,$color)); } function gd_text(&$image,$x,$y,$text,$color="000000",$font=2) { //return imagettftext ( $image, 14, 0, $x, $y, gd_hexgd($image,$color), "./arial.ttf", $text); return imagestring ($image, $font, $x, $y, $text, gd_hexgd($image,$color)); } function gd_loadfont($fname) { $f = "./templates/gdf/$fname.gdf"; if(!file_exists($f)) { echo "file not found - $f<br />"; return false; } $fn = @imageloadfont($f); if($fn === FALSE) return false; return $fn; } function gd_textwidth($font=1,$text) { $ret= 0; if($text=='') return 0; return (imagefontwidth($font) * strlen($text));// - (imagefontwidth($font)/2); } function gd_textheight($font=1) { return imagefontheight($font); } function gd_copy(&$image,$x,$y,$w,$h) { $ret=imagecreatetruecolor($w, $h); imagecopy($ret,$image, 0, 0, $x, $y, $w, $h); return $ret; } function gd_paste(&$from,$to,$x=0,$y=0) { return imagecopymerge($to, $from, $x, $x, 0, 0, imagesx($from), imagesy($from), 100); } function gd_newimage($width,$height) { return imagecreatetruecolor($width, $height); } function gd_pixeltrans(&$image,$color) { return imagecolortransparent ($image, gd_hexgd($image,$color)); } function gd_line(&$image,$x,$y,$x2,$y2,$color="000000") { return imageline($image, $x,$y,$x2,$y2,gd_hexgd($image,$color)); } function gd_rectangle(&$image,$x,$y,$w,$h,$color="000000") { $col = gd_hexgd($image,$color); imageline($image, $x,$y,$x,$y+$h,$col); //left imageline($image, $x,$y,$x+$w,$y,$col); //top imageline($image, $x+$w,$y,$x+$w,$y+$h,$col); //right imageline($image, $x,$y+$h,$x+$w,$y+$h,$col); //bottom return $image; } function gd_filledellipse(&$image,$x,$y,$w,$h,$color="ff0000") { $col = gd_hexgd($image,$color); imagefilledellipse ( $image, $x, $y, $w, $h, $col); } function gd_ellipse(&$image,$x,$y,$w,$h,$color="ff0000") { $col = gd_hexgd($image,$color); imageellipse ( $image, $x, $y, $w, $h, $col); } function gd_loadimage($fname) { //ignore ext e.g. for xbm and xpm load jpg $arr = explode(".",$fname); $ext = strtolower($arr[count($arr)-1]); $func = 'imagecreatefrom'; switch($ext) { case 'jpg' : case 'jpeg': case 'jpe' : $func .= 'jpeg'; break; case 'png' : $func .= 'png'; break; case 'gif' : $func .= 'gif'; break; case 'xbm' : $func .= 'xbm'; break; case 'wbmp': $func .= 'wbmp'; break; /*case 'gif' : $func .= 'jpeg'; break; case 'xbm' : $func .= 'jpeg'; break; case 'xpm' : $func .= 'jpeg'; break; case 'wbmp': $func .= 'wbmp'; break; case 'bmp' : $func .= 'jpeg'; break; case 'ico' : $func .= 'png'; break; case 'cur' : $func .= 'jpeg'; break; case 'ani' : $func .= 'jpeg'; break; case 'txt' : $func .= 'jpeg'; break;*/ } if(!function_exists($func)) return false; $res = @$func($fname);; if(!$res) $res = @imagecreatefromjpeg($fname); if(!$res) return false; return $res; } function gd_loadimage_orig($fname) { if(!file_exists($fname)) return false; $arr = explode(".",$fname); $ext = strtolower($arr[count($arr)-1]); if($ext=='jpe' or $ext == 'jpg') $ext = 'jpeg'; $func = "imagecreatefrom$ext"; if(!function_exists($func)) return false; //return $func($fname,$ext=='ico'?16:'',$ext=='ico'?32:100); return $func($fname); } function write_jpeg(&$image,$fname,$quality=100) { if (function_exists("imagejpeg")) return @imagejpeg($image,$fname,$quality); return false; } function write_png(&$image,$fname,$comp=9) { if (function_exists("imagejpng")) if (function_exists("imagejpng")) return @imagepng($image,$fname,$comp); return false; } function write_gif(&$image,$fname) { if (function_exists("imagegif")) return @imagegif($image,$fname); return false; }
0
#10 Dec 14th, 2009
Firstly, have you contacted the author of the script to troubleshoot?
Secondly, do you really need all this functionality or are you just wanting to crop 15px off the thumbnail? If so, this script (or library!) is totally overkill.
To be honest, trawling through all that code is a pain. I'm afraid I don't have the time for all that. Sorry.
Secondly, do you really need all this functionality or are you just wanting to crop 15px off the thumbnail? If so, this script (or library!) is totally overkill.
To be honest, trawling through all that code is a pain. I'm afraid I don't have the time for all that. Sorry.
Twpsyn cythraul. Cawr y dom tarw. Gwybod dim, gofyn dim.
![]() |
Similar Threads
- Code for Image Processing (C)
- How do you convert from a pixel array to display an image (Java)
- Help! Convert pixel array of complex numbers to image. (Java)
- image-code verification feature (PHP)
- Get Pixel values from Image (Java)
- Something wrong with scanning of intesity value of pixel image (C#)
- Upload Image Code (HTML and CSS)
- Help! Scanning through each image pixel... (Java)
Other Threads in the PHP Forum
- Previous Thread: Why imagefill always black?
- Next Thread: How to enter text into a text field for another page?
Views: 842 | Replies: 17
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache archive array arrays auto box broken buttons cakephp check checkbox class classes cms code combobox css curl database date directory display download dropdown dropdownlist drupal dynamic echo email error file files folder form forms functions header href htaccess html image include insert integration ip java javascript joomla jquery limit link login lookup loop mail menu mlm mod_rewrite multiple mysql order parse password paypal php problem query radio redirect regex remote results script search select server session shopping sort source sql string syntax table tutorial update upload url user validate validation variable video web website wordpress xml






