473,508 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help please in this code ?

56 New Member
Hi
i have image script , and images have my own watermark on the bottom , size of this watermark 15 pixel ,,, i just need help in the code below to tell php to ignore reading this watermark while creating thumbnails for the images , i just want the watermark disappear in thumbnails only
Dec 14 '09 #1
8 1602
kovik
1,044 Recognized Expert Top Contributor
I don't think anyone will try to wade through your code in order to help you *fix* it. If they do, kudos to them. Unless you have an actual error, then I'm going to ignore the code.

Basically, the process you want to follow is this:
  1. Make the main GD image and save it into a variable (main)
  2. Duplicate the GD image and save that into another variable (thumbnail)
  3. Add the watermark to the first GD image (main)
  4. Resize the second GD image to the desired thumbnail size (thumbnail)
  5. Save both images to the disk
Dec 14 '09 #2
fuchsia555
56 New Member
Thanks for replay dear kovik
but i don't need to watermark images through script
my images already watermarked with desktop software
all i need that to tell php ignore 15 pixel from height bottom while creating thumbnail , because i don't want the watermark appear in thumbnails images , i think i need something like $crop = 15 pixel
and minus it from height i don't know how to do it exactly
Dec 14 '09 #3
kovik
1,044 Recognized Expert Top Contributor
Oh, you want to crop it? Use imagecopyresampled() and utilize the src_h parameter to tell PHP what part of the image to copy.
Dec 14 '09 #4
fuchsia555
56 New Member
here is an example for image and watermark
http://img683.imageshack.us/img683/2827/example.gif

but how can we set imagecopyresampled()
in this script to work together

here is code that show how thumbnail work in my script
Expand|Select|Wrap|Line Numbers
  1. #create thumb
  2.                     $thumb = gd_fit($image,$settings['thumbxy']);
  3.  
  4.                     #save thmb first
  5.                     imagejpeg($thumb,"$th/$id.jpg",$settings['thumbuality']);
  6.                     imagedestroy($thumb);
  7.                     #then save actual jpeg
  8.                     imagejpeg($image,"$im/$id.jpg",$settings['quality']);
  9.                     imagedestroy($image);
  10.  
  11.                     $iptc = new iptc("$im/$id.jpg");
  12.                     if($cimg[0] == 1) {
  13.                         #it is gif keep in data
  14.                         write_file("$im/$id.jpg",load_file("$th/$id.jpg"));
  15.                         write_file("$im/$id.gif",$cimg[1]);
  16.                         $iptc->set(DPI_GIF,"GIF");
  17.                     }
  18.  
  19.   function gd_fit(&$image, $target) { 
  20.  
  21.         //takes the larger size of the width and height and applies the  
  22.         //formula accordingly...this is so this script will work  
  23.         //dynamically with any size image 
  24.  
  25.         $width = gd_width($image);
  26.         $height = gd_height($image);
  27.  
  28.         if ($width > $height) { 
  29.             $percentage = ($target / $width); 
  30.         } else { 
  31.             $percentage = ($target / $height); 
  32.         } 
  33.  
  34.         //gets the new value and applies the percentage, then rounds the value 
  35.         $width = round($width * $percentage); 
  36.         $height = round($height * $percentage); 
  37.  
  38.         //returns the new sizes in html image tag format...this is so you 
  39.         //can plug this function inside an image tag and just get the 
  40.  
  41.         return gd_resize($image,$width,$height);
  42.             }
  43.       function gd_width(&$image) {
  44.         return imagesx($image);
  45.     }
  46.     function gd_height(&$image) {
  47.         return imagesy($image);
  48.     }    
  49.  
  50.     function gd_imagewidth($fname) {
  51.         list($width, $height) = getimagesize($fname);         
  52.         return $width;
  53.     }
  54.     function gd_imageheight($fname) {
  55.         list($width, $height) = getimagesize($fname);         
  56.         return $height;
  57.     }       
  58.  
  59.  
  60.  
  61.         function gd_resize(&$image,$w,$h) {
  62.         $ret=@imagecreatetruecolor($w, $h); 
  63.         @imagecopyresampled ($ret,$image, 0, 0, 0, 0, $w, $h, imagesx($image), imagesy($image));  
  64.  
  65.         return $ret; 
  66.     }
  67.  
  68.  
Dec 15 '09 #5
kovik
1,044 Recognized Expert Top Contributor
  1. Use an imagecreatefrom* function (i.e. imagecreatefromjpeg()) to build the GD image resource from a file
  2. Use imagesx() and imagesy() to get the width and height of the GD image resource, respectively.
  3. Use the width, height, and imagecreatetruecolor() to build a canvas for a new image that is the desired size using the original width and height
  4. Use imagecopyresampled() to copy the desired contents of the first GD image resource (as the source) to the second GD image resource (as the destination).
  5. Use an image* function (i.e. imagejpeg()) to save the file.
Dec 15 '09 #6
fuchsia555
56 New Member
i think we're close to solve it , i will follow your steps by it's number with my codes

step 1-
Expand|Select|Wrap|Line Numbers
  1.  function gd_loadimage($fname) { //ignore ext e.g. for xbm and xpm load jpg
  2.         $arr = explode(".",$fname);
  3.         $ext = strtolower($arr[count($arr)-1]);
  4.         $func = 'imagecreatefrom';
  5.         switch($ext) {
  6.             case 'jpg' :
  7.             case 'jpeg':
  8.             case 'jpe' :  $func .= 'jpeg'; break;
  9.             case 'png' :  $func .= 'png'; break;
  10.             case 'gif' :  $func .= 'gif'; break;
  11.             case 'xbm' :  $func .= 'xbm'; break;
  12.             case 'wbmp':  $func .= 'wbmp'; break;
  13.  
  14.             /*case 'gif' :  $func .= 'jpeg'; break;
  15.             case 'xbm' :  $func .= 'jpeg'; break;
  16.             case 'xpm' :  $func .= 'jpeg'; break;
  17.             case 'wbmp':  $func .= 'wbmp'; break;
  18.             case 'bmp' :  $func .= 'jpeg'; break;
  19.             case 'ico' :  $func .= 'png'; break;
  20.             case 'cur' :  $func .= 'jpeg'; break;
  21.             case 'ani' :  $func .= 'jpeg'; break;
  22.             case 'txt' :  $func .= 'jpeg'; break;*/
  23.  
  24.  
  25.  
  26.         }
  27.         if(!function_exists($func))
  28.             return false;
  29.  
  30.         $res = @$func($fname);;
  31.         if(!$res)
  32.             $res = @imagecreatefromjpeg($fname);
  33.         if(!$res) return false;
  34.  
  35.         return $res;
  36.  
  37.     }
  38.     function gd_loadimage_orig($fname) {
  39.         if(!file_exists($fname)) return false;
  40.  
  41.         $arr = explode(".",$fname);
  42.         $ext = strtolower($arr[count($arr)-1]);
  43.  
  44.         if($ext=='jpe' or $ext == 'jpg') $ext = 'jpeg';
  45.  
  46.         $func = "imagecreatefrom$ext";            
  47.  
  48.         if(!function_exists($func)) 
  49.             return false;
  50.  
  51.         //return $func($fname,$ext=='ico'?16:'',$ext=='ico'?32:100);
  52.         return $func($fname);
  53.  
  54.     }    



step 2-
Expand|Select|Wrap|Line Numbers
  1.     function gd_width(&$image) {
  2.         return imagesx($image);
  3.     }
  4.     function gd_height(&$image) {
  5.         return imagesy($image);
  6.     }    
  7.  
  8.     function gd_imagewidth($fname) {
  9.         list($width, $height) = getimagesize($fname);         
  10.         return $width;
  11.     }
  12.     function gd_imageheight($fname) {
  13.         list($width, $height) = getimagesize($fname);         
  14.         return $height;
  15.     }  
  16.  


step 3-

creating thumb is using this code
Expand|Select|Wrap|Line Numbers
  1. #create thumb
  2. $thumb = gd_fit($image,$settings['thumbxy']);
so it's using gd_fit function , this function here
Expand|Select|Wrap|Line Numbers
  1.     function gd_fit(&$image, $target) { 
  2.  
  3.         $width = gd_width($image);
  4.         $height = gd_height($image);
  5.  
  6.         if ($width > $height) { 
  7.             $percentage = ($target / $width); 
  8.         } else { 
  9.             $percentage = ($target / $height); 
  10.         } 
  11.  
  12.         //gets the new value and applies the percentage, then rounds the value 
  13.         $width = round($width * $percentage); 
  14.         $height = round($height * $percentage); 
  15.  
  16.         //returns the new sizes in html image tag format...this is so you 
  17.         //can plug this function inside an image tag 
  18.  
  19.         return gd_resize($image,$width,$height);
  20.  
  21.     } 

step 4- the return from gd_fit >> function gd_resize ,,,, and it's code
Expand|Select|Wrap|Line Numbers
  1.  
  2.     function gd_resize(&$image,$w,$h) {
  3.         $ret=@imagecreatetruecolor($w, $h); 
  4.         @imagecopyresampled ($ret,$image, 0, 0, 0, 0, $w, $h, imagesx($image), imagesy($image));  
  5.  
  6.         return $ret; 
  7.     }
  8.  
step 5- imagejpeg and it's code >>
Expand|Select|Wrap|Line Numbers
  1.      function write_jpeg(&$image,$fname,$quality=100) {
  2.         if (function_exists("imagejpeg"))
  3.             return @imagejpeg($image,$fname,$quality); 
  4.         return false;
  5.     }


so the step number 4 that must be edit , we're close to it , i don't know exactly how to do it
Dec 15 '09 #7
kovik
1,044 Recognized Expert Top Contributor
I told you everything that you need to know, MUCH more than I even should have told you. Write the code, debug it, find out where its going wrong, THEN ask for more help.
Dec 15 '09 #8
fuchsia555
56 New Member
Thank you Mr Kovik so much
i'll try to do it
i really love this forum

Greetings and Respect
Dec 15 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3472
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
1
1915
by: the_proud_family | last post by:
HELP ME PLEASE!! my email is the_proud_family@yahoo.com I can't get the ball to go up right side and then I need it to turn around and keep turning until velocity=0 I have been at it for the ...
7
3570
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
6
2984
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
5
2963
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
23
3232
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
13
4296
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
2
1874
by: tuan_vandyk | last post by:
Hi I desperately need help with my project. Theoretically everything should work bu it just isn't. Please email me for a copy of the project's source code. It was made in Turbo C++ 5. Please if...
1
2275
by: glenn123 | last post by:
Hi, i am just about out of time to produce a working jukebox which has to perform these functions: to play music files when a track is chosen from a list which when the user presses the change genre...
5
2287
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.