473,788 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

work with images

Hi,
I wonder is there a way or a function to take a high resolution image
and change it to low resolution ?? I have a directory with a 200
pictures, and want to save them with the same width and height but with
another lower resolution, can I do it automaticly with a script, not
downloading them, changing them with image program and uploading them
again..
Thank you

Dec 11 '05 #1
8 2313
In article <11************ **********@g14g 2000cwa.googleg roups.com>,
"NurAzije" <nu******@gmail .com> wrote:
Hi,
I wonder is there a way or a function to take a high resolution image
and change it to low resolution ?? I have a directory with a 200
pictures, and want to save them with the same width and height but with
another lower resolution, can I do it automaticly with a script, not
downloading them, changing them with image program and uploading them
again..


You say you want to keep the width/height and change the resolution, which
sounds like if you want to change the DPI. This will not alter the images size
on disk at all. DPI is just a numerical value attached to an image that lets a
printer know how big it should be on paper.

As long as the pixels are the same, DPI doesn't change anything. I.e. a 200x200
pixel large image in 72 dpi is the exact same size as a 200x200 pixel large
image in 300 dpi.
Generally, though, when you talk about high/low resolution images on the web,
you are indeed talking about the image width/height in pixels. I.e. a very
large image on the web makes for printing in a higher resolution than a smaller
one.
So, the question is, when you say "the same width and height", do you mean in
pixels or a real world measurement (i.e. inches/centimeters)?

Because, if you mean in inches (as in the image being 300x300 and it's in 300
DPI and thus prints as a one-inch square on paper) you can calculate the new
pixel ratio for each image to your new resolution.
So:

300x300 pixels @ 300 dpi = 1 inch^2
150x150 pixels @ 150 dpi = 1 inch^2

So, you have to lower the DPI along with the amount of pixels to keep the end
result intact.

PHP doesn't, as far as I know, have any tools to deal with DPI information in
images. You might want to have a look at ImageMagick.
--
Sandman[.net]

Edwin, on protecting against malware:
"I use Avast AV, the Yahoo anti-spy toolbar, the MS anti-spy software,
Windows SP2 with its firewall, AdAware, Spybot Search and Destroy, and
SpywareBlaster. "
Dec 11 '05 #2
I ment the quality of images, I want them to be lighter for download,
for example, some images are 2MB in JPG, by Adobe Photoshop or
Fireworks or even Microsoft Imaging I can lower its size in MB to KB
and change in it dimensions nothing.. Do understand me now, I have a
website with images wich are too big for download..

Dec 11 '05 #3
Screen captures with LviewPro works very well for this albeit, not an
automatic process.

On 11 Dec 2005 02:46:45 -0800, "NurAzije" <nu******@gmail .com> wrote:
I ment the quality of images, I want them to be lighter for download,
for example, some images are 2MB in JPG, by Adobe Photoshop or
Fireworks or even Microsoft Imaging I can lower its size in MB to KB
and change in it dimensions nothing.. Do understand me now, I have a
website with images wich are too big for download..

Dec 11 '05 #4
*** NurAzije escribió/wrote (11 Dec 2005 02:46:45 -0800):
I ment the quality of images, I want them to be lighter for download,
for example, some images are 2MB in JPG, by Adobe Photoshop or
Fireworks or even Microsoft Imaging I can lower its size in MB to KB
and change in it dimensions nothing.. Do understand me now, I have a
website with images wich are too big for download..


So you want to increase the JPEG compression ratio in order to get smaller
files through decreasing picture quality.

In the "Image Functions" chapter in PHP manual, imagejpeg() looks like what
you're looking for. Read the whole index though, since there may be other
useful functions.

Also, there's a suite called ImageImagick with several command line tools
for image processing. It's installed in most Linux servers and is a faster
alternative to native PHP functions. You can use it via exec() or system().
--
-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro
--
Dec 11 '05 #5
VS
NurAzije wrote:
I ment the quality of images, I want them to be lighter for download,
for example, some images are 2MB in JPG, by Adobe Photoshop or
Fireworks or even Microsoft Imaging I can lower its size in MB to KB
and change in it dimensions nothing.. Do understand me now, I have a
website with images wich are too big for download..


Sounds to me like your images are just being re-sized by the application
to fit the screen and all you really need to do is re-sample/re-scale
them to reduce the on-disk size.

I have a 10x6cm Photo which for test purposes I scanned at the highest
resolution supported by my Photo Printer/Scanner this produced a 96MB
(approx) Bitmap file which is 4279x6963 pixels. When converted to JPG
this was reduced to 3MB on Disk. When this is loaded into a editor it is
initially displayed at 1/10th scale (to fit on the screen) I can reduce
the size to just 10% of the original (473x696) and it still displays at
the same size on screen, but doing so reduces the file size to 51KB.

--
VS
Dec 11 '05 #6
NurAzije wrote:
I wonder is there a way or a function to take a high resolution image
and change it to low resolution ??


imagepjeg()
Look it up on the manual: http://www.php.net/imagejpeg
not tested
<?php
define('QUALITY ', '10'); // try different values here
$filename = 'DSC09876.jpg';
$im = imagecreatefrom jpeg($filename) ;
imagejpeg($im, 'low_' . $filename, QUALITY);
?>

Dec 11 '05 #7
NurAzije wrote:
I ment the quality of images, I want them to be lighter for download,
for example, some images are 2MB in JPG, by Adobe Photoshop or
Fireworks or even Microsoft Imaging I can lower its size in MB to KB
and change in it dimensions nothing.. Do understand me now, I have a
website with images wich are too big for download..


I know (and use) 2 ways:

1) gimp - look into 'scripts fu', if you want to use that.

2) php - I'll email you my script for doing it, let me know if
you have any questions...

It works on all images (between the set number range) with a filename
of a given format - and OVERWRITES them !

So I make large/medium/small directories of the original images,
then run the script on the medium/small directories...

It scales to a 'new major' side length, so the images can be portrait
or landscape to start with.

John.

Dec 16 '05 #8
Thank you very much, I've done it, this is the script:
<?php
$ftp_server="Se rver";
$ftp_user_name= "UserName";
$ftp_user_pass= "Password";
$path="Director y_Path_of _Images";
$pathwww="FTP_D irectory_Path_o f_images";
$mode1="0777";
$mode2="0644";
$quality=70;
// set up basic connection
$conn_id = ftp_connect($ft p_server);
// login with username and password
$login_result = ftp_login($conn _id, $ftp_user_name, $ftp_user_pass) ;
//list the directory of images
$d = dir($path);
while(false !== ($e = $d->read())){
if(strpos($e,'. jpg')){
// try to chmod $file to 777
$file=$e;
$command1="CHMO D $mode1 $pathwww/$file";
$command2="CHMO D $mode2 $pathwww/$file";
@ftp_site($conn _id, $command1);
$r = imagecreatefrom jpeg($path."/".$e);
imagejpeg($r,st r_replace('.jpg ','.jpg',$e),$q uality);
@ftp_site($conn _id, $command2);
echo "Done $e<br>";
}
if(strpos($e,'. gif')){
// try to chmod $file to 777
$file=$e;
$command1="CHMO D $mode1 $pathwww/$file";
$command2="CHMO D $mode2 $pathwww/$file";
@ftp_site($conn _id, $command1);
$r = imagecreatefrom gif($path."/".$e);
imagegif($r,str _replace('.gif' ,'.gif',$e),$qu ality);
@ftp_site($conn _id, $command2);
echo "Done $e<br>";
}
if(strpos($e,'. png')){
// try to chmod $file to 777
$file=$e;
$command1="CHMO D $mode1 $pathwww/$file";
$command2="CHMO D $mode2 $pathwww/$file";
@ftp_site($conn _id, $command1);
$r = imagecreatefrom png($path."/".$e);
imagepng($r,str _replace('.png' ,'.png',$e),$qu ality);
@ftp_site($conn _id, $command2);
echo "Done $e<br>";
}
}
// close the connection
ftp_close($conn _id);
?>

Dec 29 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2079
by: Venkat | last post by:
Hi, My HTML page doesnot work properly in Netscape 7.1. But works fine in Opera 7 and IE 6.0. I could not figure out the problem. If any one could/suggest it would be nice.. This piece of HTML describes a tree like structure of the contents. Thanks venkat. ------
8
1991
by: Mark Constant | last post by:
I have a xslt file and it keeps giving me an EOF error when it reaches the point <xsl:for-each select="lc:Entertainment/lc:$Hardware"> and <xsl:for-each select="lc:Entertainment/lc:$Hardware"> My xslt file looks like this <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
1751
by: SC | last post by:
I have two identical textboxes and two identical images that go are next to them. Only the names are different. I have onBlur trigger a function to make sure the boxes were not left empty. If a textbox was left empty, the image to the left of the box would be a warning icon. If an entry was made in the textbox, that image would be a transparent GIF. The function works great on the other 18 form fields. It only fails to work in IE on the...
13
2368
by: LRW | last post by:
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected. Here's what I have: function checkdel() { if (document.getElementById"].value=='1') { confirm('Are you sure you want to delete this file?'); } } ......
1
2041
by: laurakr | last post by:
I am trying to use a clear to get my bottom nav bar below the quote box on the right, but it isn't working. I would like the bottom edge of the quote box to "stick" to the footer nav bar but copy to be able to flow to the left of the quote box. For the bonus round I would like the right edge of the box to align with the right edge of the footer Could someone take a look at my code and help a newbie troubleshoot? my email is lroeder at...
7
8929
by: Papelotte | last post by:
Hi all, I'm new to this forum and I am hoping that there is someone here who can help me. I have an ASP page that has javascript that works perfectly in IE, but not in Firefox. Can anybody tell me how to get it to work in FF. I can insert a browser identifier and redirect if the script has to change for FF only. Basically, when a vistor goes to the page they are asked to click on images to chose the top 3 that they like - the images...
2
2893
by: Jim Carr | last post by:
Upon entering the site www.FutureByDesign-Music.com with IE6, my clipboard is erased and then disabled in all other Windows XP applications. Navigating to another site returns clipboard functionality, but whatever was on the clipboard before is lost. If I disable running JavaScript on the page, the clipboard is unaffected. Viewing the page in Firefox does not have this issue. I think it might be the script below, which makes no sense...
10
7078
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for only small sized iamages.. for eg. resizing takes place for 70 kb sized images but fails for 600kb or more.. my code is below..
15
3078
by: colyn7 | last post by:
I really can't see what's wrong in my code... the submit() onChange doesn't work.. I've tried.. <select name="ddlTestCenter" id="ddlTestCenter" style="width:180px" onChange="this.form.submit();"> it doesn't work... <input type="hidden" name="hiddenopt" value="secret"> <select name="list" onChange="document.forms.submit();">
4
2507
by: z55177 | last post by:
My domain: http://www.esthevision.cz/ This is the cause of my problem. The template is supposed to look somewhat like this: PINK STRIPE http://themebot.com/website-templates/ht... I created an extra copy of it called Natvrdo, since I modified the logo. Okay, I have this in my HTML (Natvrdo being the CSS style sheet) This is what I have in my index.html:
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.