private function readUrl_Curl($url, $destFile, ImThumb $requestor)
 {
     self::$curlFH = @fopen($destFile, 'w');
     if (!self::$curlFH) {
         throw new ImThumbException('Could not open cache file for remote image', ImThumb::ERR_CACHE);
     }
     self::$curlDataWritten = 0;
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_TIMEOUT, $requestor->param('externalRequestTimeout'));
     curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30");
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($curl, CURLOPT_WRITEFUNCTION, 'ImThumbSource_HTTP::curlWrite');
     @curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
     @curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
     $curlResult = curl_exec($curl);
     $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     fclose(self::$curlFH);
     curl_close($curl);
     if ($httpStatus == 404) {
         throw new ImThumbNotFoundException('Could not locate remote image', ImThumb::ERR_SRC_IMAGE);
     }
     if ($httpStatus == 302) {
         throw new ImThumbNotFoundException("External Image is Redirecting. Try alternate image url", ImThumb::ERR_SRC_IMAGE);
     }
     if (!$curlResult) {
         throw new ImThumbException("Internal cURL error fetching remote file", ImThumb::ERR_SRC_IMAGE);
     }
 }
Exemplo n.º 2
0
 public function validateWith(ImThumb $generator)
 {
     if (!$this->valid) {
         throw new ImThumbNotFoundException("Could not read image metadata", ImThumb::ERR_SRC_IMAGE);
     }
     if ($this->fileSize > $generator->param('maxSize')) {
         throw new ImThumbException("Image file exceeds maximum processable size", ImThumb::ERR_SRC_IMAGE);
     }
 }
 public function readMetadata($src, ImThumb $requestor)
 {
     $fallbackMeta = new ImThumbMeta();
     $src = $this->getRealImagePath($src, $requestor->param('baseDir'));
     $mtime = @filemtime($src);
     if (false === $mtime) {
         return $fallbackMeta->invalid();
     }
     $fileSize = @filesize($src);
     $sData = @getimagesize($src);
     // ensure it's an image
     if (!$sData) {
         return $fallbackMeta->invalid();
     }
     $mimeType = strtolower($sData['mime']);
     if (!preg_match('/^image\\//i', $mimeType)) {
         $mimeType = 'image/' . $mimeType;
     }
     if ($mimeType == 'image/jpg') {
         $mimeType = 'image/jpeg';
     }
     return new ImThumbMeta($src, $mtime, $fileSize, $mimeType);
 }
Exemplo n.º 4
0
 public function getCachePath(ImThumb $imageHandle, $src = null)
 {
     $cacheDir = $this->baseDir;
     if (!$cacheDir) {
         return false;
     }
     if (!$src) {
         $src = $imageHandle->getSrc();
     }
     $extension = substr($src, strrpos($src, '.') + 1);
     if ($this->cacheFilenameFormat) {
         list($width, $height) = $imageHandle->getTargetSize();
         return $cacheDir . '/' . str_replace(array('%filename%', '%ext%', '%w%', '%h%', '%q%', '%a%', '%zc%', '%s%', '%cc%', '%ct%', '%cr%', '%filters%', '%pjpg%', '%upscale%'), array(basename($src, '.' . $extension), $extension, $width, $height, $imageHandle->param('quality'), $imageHandle->param('align'), $imageHandle->param('cropMode'), $imageHandle->param('sharpen') ? 's' : '', $imageHandle->param('canvasColor'), $imageHandle->param('canvasTransparent') ? 't' : '', $imageHandle->param('cropRect'), $imageHandle->param('filters'), $imageHandle->param('jpgProgressive') ? 'p' : '', $imageHandle->param('upscale') ? '' : 'nu'), $this->cacheFilenameFormat);
     }
     return $cacheDir . '/' . $this->cachePrefix . md5($this->cacheSalt . json_encode($imageHandle->params()) . ImThumb::VERSION) . $this->cacheSuffix;
 }