In onderstaande code worden alle foto's geupload naar 1000 * 750 pixels. Maar we willen graag dat de afbeelding zijn afmeting behoudt. Weet iemand welke aanpassing ik moet doen in dit script?
Alvast bedankt, Diederik
PHP Code:
$photoFileName = $_FILES['product_image']['name'];
if ($photoFileName) {
$aFileNameParts = explode(".", $photoFileName);
$sFileExtension = end($aFileNameParts);
$sTempFileName = $_FILES['product_image']['tmp_name']; // temporary file at server side
$oTempFile = fopen($sTempFileName, "r");
$sBinaryPhoto = fread($oTempFile, fileSize($sTempFileName));
// Try to read image
$old_error_reporting = error_reporting(E_ALL & ~(E_WARNING)); // ingore warnings
$oSourceImage = imagecreatefromstring($sBinaryPhoto); // try to create image
error_reporting($old_error_reporting);
$nWidth = imagesx($oSourceImage); // get original source image width
$nHeight = imagesy($oSourceImage); // and height
// create small thumbnail
$nDestinationWidth = 1000;
$nDestinationHeight = 750;
$oDestinationImage = imagecreatetruecolor($nDestinationWidth, $nDestinationHeight);
/*$oResult = imagecopyresampled(
$oDestinationImage, $oSourceImage,
0, 0, 0, 0,
$nDestinationWidth, $nDestinationHeight,
$nWidth, $nHeight); // resize the image
*/
imagecopyresized(
$oDestinationImage, $oSourceImage,
0, 0, 0, 0,
$nDestinationWidth, $nDestinationHeight,
$nWidth, $nHeight); // resize the image
ob_start(); // Start capturing stdout.
imageJPEG($oDestinationImage); // As though output to browser.
$sBinaryThumbnail = ob_get_contents(); // the raw jpeg image data.
ob_end_clean(); // Dump the result so it does not screw other output.
$sBinaryThumbnail = addslashes($sBinaryThumbnail);
mysql_query("
INSERT INTO `quattrocms_photo_photos` (
`photo_id`,
`photo_company_id`,
`photo_album_id`,
`photo_type`,
`photo_date`,
`photo_time`,
`photo_rssdate`,
`photo_title`,
`photo_description`,
`photo_image`
) VALUES (
NULL,
'".$_COOKIE['login_company_id']."',
'".$_GET['id']."',
'1',
'".date('d-m-Y')."',
'".date('H:i')."',
'".date('D, d M Y H:i:s O')."',
'".addslashes($_POST['photo_title'])."',
'".addslashes($_POST['editor'])."',
'".$sBinaryThumbnail."'
);
");
Header ("Location: ./?do=".$_GET['do']."");
}
- Upload script vraagje
-
28-01-2010, 14:12 #1
- Berichten
- 400
- Lid sinds
- 15 Jaar
Upload script vraagje
-
-
28-01-2010, 17:33 #2
- Berichten
- 1.344
- Lid sinds
- 18 Jaar
Het simpelste oplossing is:
$nDestinationWidth = 1000;
$nDestinationHeight = 750;
Veranderen in
$nDestinationWidth = $nWidth;
$nDestinationHeight = $nHeight;
-
31-01-2010, 20:05 #3
- Berichten
- 533
- Lid sinds
- 16 Jaar
-
31-01-2010, 20:34 #4
- Berichten
- 6
- Lid sinds
- 15 Jaar
Ik heb dit gisteren nog voor asp.net geschreven, komt erop neer dat ik kijk wat het grootste is (breedte of hoogte), dan een verkleiningsfactor bepalen en toepassen op beiden.
Tags voor dit bericht
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic